Beispiel #1
0
 def trust_asset(setup, secret_key, memo_text=None):
     """A helper to establish a trustline"""
     builder = Builder(secret=secret_key,
                       horizon_uri=setup.horizon_endpoint_uri,
                       network=setup.network)
     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 = builder.submit()
     return reply.get('hash')
Beispiel #2
0
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
Beispiel #3
0
 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')
def test_create():
    seed = 'SASKOJJOG7MLXAWJGE6QNCWH5ZIBH5LWQCXPRGDHUKUOB4RBRWXXFZ2T'
    address = 'GCAZ7QXD6UJ5NOVWYTNKLNP36DPJZMRO67LQ4X5CH2IHY3OG5QGECGYQ'

    # with secret
    builder = Builder(secret=seed, network_name=None, horizon=None, fee=100)
    assert builder
    assert builder.keypair.seed().decode() == seed
    assert builder.address == address
Beispiel #5
0
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
Beispiel #6
0
 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')
Beispiel #7
0
 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')
Beispiel #8
0
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)
Beispiel #9
0
from kin_base.builder import Builder

alice_seed = 'SB4675LMYLBWMKENDBAO6ZTVPLI6AISE3VZZDZASUFWW2T4MEGKX7NEI'
bob_address = 'GCRNOBFLTGLGSYOWCYINZA7JAAAZ5CXMSNM7QUYFYOHHIEZY4R6665MA'

selling_code = 'XLM'
selling_issuer = None

buying_code = 'XCN'
buying_issuer = 'GCNY5OXYSY4FKHOPT2SPOQZAOEIGXB5LBYW3HVU3OWSTQITS65M5RCNY'

price = '5.5'  # or price = {'n': 55, 'd': 10}
amount = '12.5'

builder = Builder(secret=alice_seed, horizon_uri='https://horizon-testnet.stellar.org') \
             .append_manage_offer_op(selling_code, selling_issuer, buying_code, \
              buying_issuer, amount, price)

builder.sign()
builder.submit()
def test_create_fail():
    with pytest.raises(StellarSecretInvalidError):
        Builder(secret='bad', network_name=None, horizon=None, fee=100)
async def test_builder_xdr(setup, helpers, test_data, aio_session):
    hot = Keypair.random()
    hot_account = hot.address().decode()
    hot_secret = hot.seed()

    await helpers.fund_account(setup, hot_account, aio_session)

    cold = Builder(secret=test_data.cold_secret, horizon=test_data.horizon, network_name=setup.network, fee=100) \
        .append_change_trust_op('BEER', test_data.cold_account, '1000', hot_account) \
        .append_allow_trust_op(hot_account, 'BEER', True, test_data.cold_account) \
        .append_payment_op(hot_account, '100', 'BEER', test_data.cold_account, test_data.cold_account) \
        .append_payment_op(test_data.cold_account, '2.222', 'BEER', test_data.cold_account, hot_account)
    await cold.update_sequence()
    cold.sign()

    xdr = cold.gen_xdr()

    hot = Builder(
        secret=hot_secret,
        horizon=test_data.horizon,
        network_name=setup.network, fee=100)
    hot.import_from_xdr(xdr)
    hot.sign()

    assert len(hot.te.signatures) == 2
    assert len(hot.ops) == 4

    response = await hot.submit()
    assert response.get('hash') == hot.hash_hex()
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 test_builder(test_data, setup):
    builder = Builder(secret=test_data.cold_secret,
                      horizon=test_data.horizon,
                      network_name=setup.network,
                      fee=100)
    return builder
Beispiel #14
0
def test_builder_xdr(setup, helpers, test_data):
    hot = Keypair.random()
    hot_account = hot.address().decode()
    hot_secret = hot.seed()

    helpers.fund_account(setup, hot_account)

    cold = Builder(secret=test_data.cold_secret, horizon_uri=setup.horizon_endpoint_uri, network=setup.network) \
        .append_change_trust_op('BEER', test_data.cold_account, '1000', hot_account) \
        .append_allow_trust_op(hot_account, 'BEER', True, test_data.cold_account) \
        .append_payment_op(hot_account, '100', 'BEER', test_data.cold_account, test_data.cold_account) \
        .append_payment_op(test_data.cold_account, '2.222', 'BEER', test_data.cold_account, hot_account)
    cold.sign()

    xdr = cold.gen_xdr()

    hot = Builder(secret=hot_secret,
                  horizon_uri=setup.horizon_endpoint_uri,
                  network=setup.network)
    hot.import_from_xdr(xdr)
    hot.sign()

    assert len(hot.te.signatures) == 2
    assert len(hot.ops) == 4

    response = hot.submit()
    assert response.get('hash') == hot.hash_hex()
Beispiel #15
0
from kin_base.builder import Builder

alice_secret = 'SCB6JIZUC3RDHLRGFRTISOUYATKEE63EP7MCHNZNXQMQGZSLZ5CNRTKK'
bob_address = 'GA7YNBW5CBTJZ3ZZOWX3ZNBKD6OE7A7IHUQVWMY62W2ZBG2SGZVOOPVH'

builder = Builder(secret=alice_secret,
                  horizon_uri='https://horizon.stellar.org',
                  network='PUBLIC')
builder.add_text_memo("Hello, Stellar!").append_payment_op(
    destination=bob_address, amount='12.25', asset_code='KIN')
builder.sign()
response = builder.submit()
print(response)