def main(source, name): # Constellation HOST = '127.0.0.1' PORT = 8100 # deploy the contract to the network api = LedgerApi(HOST, PORT) # api = LedgerApi(network='alphanet') # Create keypair for the contract owner owner = Entity() owner_addr = Address(owner) # print(owner_addr) # Need funds to deploy contract api.sync(api.tokens.wealth(owner, 20000)) # Create contract contract = Contract(source, owner) # Deploy contract api.sync(api.contracts.create(owner, contract, 10000)) # Save the contract to the disk with open('sample.contract', 'w') as contract_file: contract.dump(contract_file) # Save the contract owner's private key to disk with open('owner_private.key', 'w') as private_key_file: owner.dump(private_key_file) print(f"Contract {name}.etch has successfully been deployed.")
def makeClient(number: int): #check if entity has already been created if (os.path.exists('./workdir/Agent_Auction/client/client' + str(number) + '_private.key')): #locate the agent account entity for interacting with the ledger. with open( './workdir/Agent_Auction/client/client' + str(number) + '_private.key', 'r') as private_key_file: client_agentID = Entity.load(private_key_file) else: #create new entity for the agent client_agentID = Entity() #store private key of newly formed entity with open( './workdir/Agent_Auction/client/client' + str(number) + '_private.key', 'w') as private_key_file: client_agentID.dump(private_key_file) #give the account starting tokens api.sync(api.tokens.wealth(client_agentID, 1000)) startBalance = api.tokens.balance(client_agentID) price = random.randint(25, 100) interval = random.randint(5, 20) # define an OEF Agent client = client_agent.ClientAgent(str(Address(client_agentID)), price, interval, client_agentID, oef_addr="127.0.0.1", oef_port=10000) print('Balance Before:', startBalance) # connect it to the OEF Node client.connect() # query OEF for DataService providers echo_query1 = Query( [Constraint("timezone", Eq(3)), Constraint("twentyfour", Eq(False))], TIME_AGENT()) client.search_services(0, echo_query1) client.run()
def add_key(self, name: str, password: str, entity: Entity): if name in self.list_keys(): raise DuplicateKeyNameError() key_file_path = self._format_key_path(name) assert not os.path.exists(key_file_path) # dump out the file with open(key_file_path, 'w') as key_file: entity.dump(key_file, password) # update the index self._index['key'].append({ 'name': name, 'address': str(Address(entity)), }) self._flush_index()
def main(): print('Creating private key...') # create our first private key pair entity1 = Entity() # save the private key to disk with open('private.key', 'w') as private_key_file: entity1.dump(private_key_file) print('Creating private key...complete') # build the ledger API api = LedgerApi('127.0.0.1', 8000) print('Creating initial balance...') # create wealth so that we have the funds to be able to create contracts on the network api.sync(api.tokens.wealth(entity1, 10000)) print('Creating initial balance...complete')
def main(): api = LedgerApi('127.0.0.1', 8100) print('Generating keys...') entity1 = Entity() with open('./workdir/UberX/server_private.key', 'w') as private_key_file: entity1.dump(private_key_file) entity2 = Entity() with open('./workdir/UberX/client_private.key', 'w') as private_key_file: entity2.dump(private_key_file) print('Generating keys...complete') print('Adding Funds...') api.sync(api.tokens.wealth(entity2, 1000)) print('Adding Funds...complete')
#define the ledger parameters api = LedgerApi('127.0.0.1', 8100) #check if entity has already been created if(os.path.exists('./workdir/Agent4/client/client_private.key')): #locate the agent account entity for interacting with the ledger. with open ('./workdir/Agent4/client/client_private.key', 'r') as private_key_file: client_agentID = Entity.load(private_key_file) else: #create new entity for the agent client_agentID = Entity() #store private key of newly formed entity with open('./workdir/Agent4/client/client_private.key', 'w') as private_key_file: client_agentID.dump(private_key_file) #give the account starting tokens api.sync(api.tokens.wealth(client_agentID, 2000)) startBalance = api.tokens.balance(client_agentID) # define an OEF Agent client_agent = ClientAgent(str(Address(client_agentID)), oef_addr="127.0.0.1", oef_port=10000) print('Balance Before:', startBalance) highest_price = 1700 if highest_price > api.tokens.balance(client_agentID): highest_price = api.tokens.balance(client_agentID) currentPrice = 0
#define the ledger parameters api = LedgerApi('127.0.0.1', 8100) #checl if entity has already been generated if(os.path.exists('./workdir/Agent_Auction/agent/server_private.key')): #locate the agent account entity for interacting with the ledger. with open ('./workdir/Agent_Auction/agent/server_private.key', 'r') as private_key_file: server_agentID = Entity.load(private_key_file) else: #create the enity for the agent server_agentID = Entity() #store the private key of the newly created entity with open('./workdir/Agent_Auction/agent/server_private.key', 'w') as private_key_file: server_agentID.dump(private_key_file) startBalance = api.tokens.balance(server_agentID) #set trading values price = 20 fet_tx_fee = 40 print('Price:', price) print('Balance Before:', startBalance) # create agent and connect it to OEF server_agent = Demo_Agent(str(Address(server_agentID)), oef_addr="127.0.0.1", oef_port=10000) server_agent.scheme['timezone'] = 3 server_agent.scheme['id'] = str(uuid.uuid4()) server_agent.scheme['twentyfour'] = False