def main():
    print('Loading private key...')

    # load up the previously created private key
    with open('private.key', 'r') as private_key_file:
        entity1 = Entity.prompt_load(private_key_file)

    print('Loading private key...complete')

    # build the ledger API
    api = LedgerApi('127.0.0.1', 8000)

    # create the smart contract
    contract = Contract(CONTRACT_TEXT, entity1)

    print('Deploying contract...')

    # deploy the contract to the network
    api.sync(api.contracts.create(entity1, contract, 2000))

    print('Deploying contract...complete')

    # save the contract to the disk
    with open('sample.contract', 'w') as contract_file:
        contract.dump(contract_file)
예제 #2
0
class SynergeticContractTestHelper:
    def __init__(self, name, api, entity, workdir="."):
        self._api = api
        self._entity = entity
        self._name = name
        self.contract = None
        self._workdir = workdir

    def create_new(self, fee_limit):
        self.contract = Contract(_CONTRACT_TEXT, self._entity)
        print('Creating contract..')
        self._api.sync(self._api.contracts.create(
            self._entity, self.contract, fee_limit))
        if len(self._name) > 0:
            with open(self._workdir+"/"+self._name+".json", "w") as f:
                self.contract.dump(f)

    def load(self):
        print('Loading contract..')
        with open(self._workdir+"/"+self._name+".json", "r") as f:
            self.contract = Contract.load(f)

    def submit_random_data(self, n, number_range, hold_state_sec=10):
        # create a whole series of random data to submit to the DAG
        random_ints = [random.randint(*number_range) for _ in range(n)]
        txs = [self._api.contracts.submit_data(self._entity, self.contract.address, value=value)
               for value in random_ints]
        self._api.sync(txs, hold_state_sec=hold_state_sec,
                       extend_success_status=["Submitted"])
        print('Data submitted.')

    def validate_execution(self):
        result = self.contract.query(self._api, 'query_result')
        return result != -1
예제 #3
0
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.")