def register_name(name, address, external_api, internal_api, private_key): salt = 42 commitment_id = internal_api.get_commitment_id(name, salt).commitment_id # preclaim unsigned_preclaim = common.base58_decode(\ internal_api.post_name_preclaim(\ NamePreclaimTx(commitment_id=commitment_id, fee=1, ttl=100, account_id=address)).tx) signed_preclaim = keys.sign_encode_tx(unsigned_preclaim, private_key) common.ensure_transaction_posted(external_api, signed_preclaim) # claim encoded_name = common.encode_name(name) unsigned_claim = common.base58_decode(\ internal_api.post_name_claim(\ NameClaimTx(name=encoded_name, name_salt=salt, fee=1, ttl=100, account_id=address)).tx) signed_claim = keys.sign_encode_tx(unsigned_claim, private_key) common.ensure_transaction_posted(external_api, signed_claim) name_entry0 = external_api.get_name_entry_by_name(name) # set pointers pointers = [NamePointer(key='account_pubkey', id=address)] unsigned_update = common.base58_decode(\ internal_api.post_name_update(\ NameUpdateTx(name_id=name_entry0.id, name_ttl=6000, client_ttl=50,\ pointers=pointers, fee=1, ttl=100, account_id=address)).tx) signed_update = keys.sign_encode_tx(unsigned_update, private_key) common.ensure_transaction_posted(external_api, signed_update) name_entry = external_api.get_name_entry_by_name(name) received_pointers = name_entry.pointers[0] assert_equals('account_pubkey', received_pointers.key) assert_equals(address, received_pointers.id)
def register_name(name, address, external_api, internal_api, private_key, fee, name_fee): salt = 42 commitment_id = internal_api.GetCommitmentId( name=name, salt=salt).response().result.commitment_id # preclaim NamePreclaimTx = internal_api.get_model('NamePreclaimTx') preclaim_tx = NamePreclaimTx(commitment_id=commitment_id, fee=fee, ttl=100, account_id=address) encoded_preclaim = internal_api.PostNamePreclaim( body=preclaim_tx).response().result.tx unsigned_preclaim = common.api_decode(encoded_preclaim) signed_preclaim = keys.sign_encode_tx(unsigned_preclaim, private_key) common.ensure_transaction_posted(external_api, signed_preclaim) # claim encoded_name = common.encode_name(name) NameClaimTx = internal_api.get_model('NameClaimTx') claim_tx = NameClaimTx(name=encoded_name, name_salt=salt, fee=fee, name_fee=name_fee, ttl=100, account_id=address) encoded_claim = internal_api.PostNameClaim( body=claim_tx).response().result.tx unsigned_claim = common.api_decode(encoded_claim) signed_claim = keys.sign_encode_tx(unsigned_claim, private_key) common.ensure_transaction_posted(external_api, signed_claim) name_entry0 = external_api.GetNameEntryByName(name=name).response().result # set pointers NameUpdateTx = internal_api.get_model('NameUpdateTx') NamePointer = internal_api.get_model('NamePointer') pointers = [NamePointer(key='account_pubkey', id=address)] name_update_tx = NameUpdateTx(name_id=name_entry0.id, name_ttl=6000, client_ttl=50,\ pointers=pointers, fee=fee, ttl=100, account_id=address) encoded_name_update = internal_api.PostNameUpdate( body=name_update_tx).response().result.tx unsigned_update = common.api_decode(encoded_name_update) signed_update = keys.sign_encode_tx(unsigned_update, private_key) common.ensure_transaction_posted(external_api, signed_update) name_entry = external_api.GetNameEntryByName(name=name).response().result received_pointers = name_entry.pointers[0] assert_equals('account_pubkey', received_pointers.key) assert_equals(address, received_pointers.id)
def register_name(name, address, external_api, private_key): salt = 42 commitment = external_api.get_commitment_hash(name, salt).commitment # preclaim unsigned_preclaim = common.base58_decode(\ external_api.post_name_preclaim(\ NamePreclaimTx(commitment=commitment, fee=1, account=address)).tx) signed_preclaim = keys.sign_encode_tx(unsigned_preclaim, private_key) external_api.post_tx(Tx(tx=signed_preclaim)) top = external_api.get_top() common.wait_until_height(external_api, top.height + 3) # claim encoded_name = common.encode_name(name) unsigned_claim = common.base58_decode(\ external_api.post_name_claim(\ NameClaimTx(name=encoded_name, name_salt=salt, fee=1, account=address)).tx) signed_claim = keys.sign_encode_tx(unsigned_claim, private_key) external_api.post_tx(Tx(tx=signed_claim)) top = external_api.get_top() common.wait_until_height(external_api, top.height + 3) name_entry0 = external_api.get_name(name) print("Name " + name_entry0.name + " has been claimed and has hash " + name_entry0.name_hash) # set pointers pointers_str = json.dumps({'account_pubkey': address}) unsigned_update = common.base58_decode(\ external_api.post_name_update(\ NameUpdateTx(name_hash=name_entry0.name_hash, name_ttl=600000, ttl=50,\ pointers=pointers_str, fee=1, account=address)).tx) signed_update = keys.sign_encode_tx(unsigned_update, private_key) external_api.post_tx(Tx(tx=signed_update)) top = external_api.get_top() common.wait_until_height(external_api, top.height + 3) name_entry = external_api.get_name(name) received_pointers = json.loads(name_entry.pointers) assert_equals(address, received_pointers['account_pubkey'])
def register_name(name, address, external_api, private_key): salt = 42 commitment_id = external_api.get_commitment_hash(name, salt).commitment_id # preclaim unsigned_preclaim = common.base58_decode(\ external_api.post_name_preclaim(\ NamePreclaimTx(commitment_id=commitment_id, fee=1, ttl=100, account_id=address)).tx) signed_preclaim = keys.sign_encode_tx(unsigned_preclaim, private_key) external_api.post_tx(Tx(tx=signed_preclaim)) top = external_api.get_top_block() common.wait_until_height(external_api, top.height + 3) # claim encoded_name = common.encode_name(name) unsigned_claim = common.base58_decode(\ external_api.post_name_claim(\ NameClaimTx(name=encoded_name, name_salt=salt, fee=1, ttl=100, account_id=address)).tx) signed_claim = keys.sign_encode_tx(unsigned_claim, private_key) external_api.post_tx(Tx(tx=signed_claim)) top = external_api.get_top_block() common.wait_until_height(external_api, top.height + 3) name_entry0 = external_api.get_name(name) # set pointers pointers = [ NamePointer(key='account_pubkey', id=address) ] unsigned_update = common.base58_decode(\ external_api.post_name_update(\ NameUpdateTx(name_id=name_entry0.id, name_ttl=6000, client_ttl=50,\ pointers=pointers, fee=1, ttl=100, account_id=address)).tx) signed_update = keys.sign_encode_tx(unsigned_update, private_key) external_api.post_tx(Tx(tx=signed_update)) top = external_api.get_top_block() common.wait_until_height(external_api, top.height + 3) name_entry = external_api.get_name(name) received_pointers = name_entry.pointers[0] assert_equals('account_pubkey', received_pointers.key) assert_equals(address, received_pointers.id)