def send_asset(cls, setup, secret_key, address, amount, memo_text=None): """A helper to send asset""" builder = Builder(secret=secret_key, horizon_uri=setup.horizon_endpoint_uri, network=setup.network) builder.append_payment_op(address, amount, setup.test_asset.code, setup.test_asset.issuer) if memo_text: builder.add_text_memo(memo_text[:28]) # max memo length is 28 builder.sign() reply = builder.submit() return reply.get('hash')
async def trust_asset(setup, secret_key, memo_text=None): """A helper to establish a trustline""" async with Horizon(setup.horizon_endpoint_uri) as horizon: builder = Builder(secret=secret_key, horizon=horizon, network_name=setup.network, fee=100) builder.append_trust_op(setup.test_asset.issuer, setup.test_asset.code) if memo_text: builder.add_text_memo(memo_text[:28]) # max memo length is 28 builder.sign() reply = await builder.submit() return reply.get('hash')
def setup_threshold(): builder = Builder(dav_seed).append_set_options_op( source=dav_kp.address().decode(), high_threshold=3, med_threshold=3, low_threshold=3, master_weight=1, signer_type='ed25519PublicKey', signer_weight=1, signer_address=alice_kp.address().decode()).append_set_options_op( source=dav_kp.address().decode(), signer_type='ed25519PublicKey', signer_weight=1, signer_address=bob_kp.address().decode( )) # append more signers here builder.sign() resp = builder.submit() return resp
async def send_asset(cls, setup, secret_key, address, amount, memo_text=None): """A helper to send asset""" async with Horizon(setup.horizon_endpoint_uri) as horizon: builder = Builder(secret=secret_key, horizon=horizon, network_name=setup.network, fee=100) builder.append_payment_op(address, amount, setup.test_asset.code, setup.test_asset.issuer) if memo_text: builder.add_text_memo(memo_text[:28]) # max memo length is 28 builder.sign() reply = await builder.submit() return reply.get('hash')
async def test_builder_(setup, test_data): hot = Keypair.random() hot_account = hot.address().decode() hot_secret = hot.seed() cold = Builder(secret=test_data.cold_secret, horizon=test_data.horizon, network_name=setup.network, fee=100) \ .append_create_account_op(hot_account, '200') \ .append_set_options_op(inflation_dest=test_data.cold_account, set_flags=1, home_domain='256kw.com', master_weight=10, low_threshold=5, ) \ .append_change_trust_op('BEER', test_data.cold_account, '1000', hot_account) \ .append_allow_trust_op(hot_account, 'BEER', True) # append twice for test cold.append_payment_op(hot_account, '50.123', 'BEER', test_data.cold_account) \ .append_payment_op(hot_account, '50.123', 'BEER', test_data.cold_account) # TODO: append_bump_sequence_op test await cold.update_sequence() cold.sign() cold.sign(hot_secret) # try to sign twice with pytest.raises(SignatureExistError): cold.sign(hot_secret) assert len(cold.te.signatures) == 2 assert len(cold.ops) == 5 response = await cold.submit() assert response.get('hash') == cold.hash_hex()
def payment(): min_time = int(time.time()) - 10 max_time = min_time + 100 time_bounds = {'minTime': min_time, 'maxTime': max_time} # time_bounds = [min_time, max_time] # v0.1.x builder = Builder(dav_seed).add_time_bounds(time_bounds=time_bounds) \ .append_payment_op(destination=eve_address, amount='100', asset_code='KIN', asset_issuer=None) builder.sign() # signed by dav with default seed builder.sign(alice_seed) # signed by alice builder.sign(bob_seed) # signed by bob resp = builder.submit() return resp
from kin_base.keypair import Keypair from kin_base.asset import Asset from kin_base.builder import Builder # Keys for accounts to issue and receive the new asset issuing_secret = 'SCBHQEGSNBTT4S7Y73YAF3M3JSVSTSNBGAVU5M4XVFGUF7664EUXQHFU' issuing_public = Keypair.from_seed(issuing_secret).address().decode() receiving_secret = 'SB6MJ6M3BPJZUGFP2QCODUIKWQWF6AIN4Z6L3J6PWL3QGDW4L6YR3QIU' receiving_public = Keypair.from_seed(receiving_secret).address().decode() # Create an object to represent the new asset my_asset = Asset('Hello', issuing_public) # First, the receiving account must trust the asset builder = Builder(receiving_secret, network='TESTNET').append_trust_op( destination=my_asset.issuer, code=my_asset.code) builder.sign() resp = builder.submit() print(resp) # Second, the issuing account actually sends a payment using the asset builder = Builder(issuing_secret, network='TESTNET').append_payment_op( destination=receiving_public, amount='1000', asset_code=my_asset.code, asset_issuer=my_asset.issuer) builder.sign() resp = builder.submit() print(resp)