示例#1
0
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)
示例#2
0
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'])
示例#3
0
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)