コード例 #1
0
ap = argparse.ArgumentParser()
ap.add_argument('-s', '--sender', required=True, help='The base58-encoded private seed of the sender account')
ap.add_argument('-d', '--destinations', required=True,
                help='A comma-delimited list of base58-encoded account addresses to send earns to '
                     '(e.g. add1,addr2,add3)')
args = vars(ap.parse_args())

client = Client(Environment.TEST, 1)  # 1 is the test app index

source = PrivateKey.from_base58(args['sender'])
destinations = [PublicKey.from_base58(addr) for addr in args['destinations'].split(',')]

# Send an earn batch with 1 Kin each
earns = [Earn(dest, kin_to_quarks('1')) for idx, dest in enumerate(destinations)]
batch_result = client.submit_earn_batch(EarnBatch(source, earns))
if batch_result.tx_error:
    print(f'{batch_result.tx_id} failed with error {repr(batch_result.tx_error)}')

    if batch_result.earn_errors:
        for e in batch_result.earn_errors:
            print(f'earn {e.earn_index} failed with error {repr(e.error)}')
else:
    print(f'{batch_result.tx_id} submitted')

# Send an earn batch of earns with 1 Kin each, with invoices
earns = [Earn(dest, kin_to_quarks('1'), invoice=Invoice([LineItem(f'Payment {idx}', kin_to_quarks('1'))]))
         for idx, dest in enumerate(destinations)]
batch_result = client.submit_earn_batch(EarnBatch(source, earns))
if batch_result.tx_error:
    print(f'{batch_result.tx_id} failed with error {repr(batch_result.tx_error)}')
コード例 #2
0
    'A comma-delimited list of account public addresses to send earns to (e.g. add1,addr2,add3'
)
args = vars(ap.parse_args())

client = Client(Environment.TEST, 1)  # 1 is the test app index

source = PrivateKey.from_string(args['sender'])
destinations = [
    PublicKey.from_string(addr) for addr in args['destinations'].split(',')
]

# Send an earn batch with 1 Kin each
earns = [
    Earn(dest, kin_to_quarks('1')) for idx, dest in enumerate(destinations)
]
batch_result = client.submit_earn_batch(source, earns)
print(
    f'{len(batch_result.succeeded)} succeeded, {len(batch_result.failed)} failed'
)
for result in batch_result.succeeded:
    print(
        f'Sent 1 kin to {result.earn.destination.stellar_address} in transaction {result.tx_id.hex()}'
    )
for result in batch_result.failed:
    print(
        f'Failed to send 1 kin to {result.earn.destination.stellar_address} in transaction {result.tx_id.hex()} '
        f'(error: {repr(result.error)})')

# Send an earn batch of earns with 1 Kin each, with invoices
earns = [
    Earn(dest,
コード例 #3
0
tx_id = submit_payment(Payment(sender, airdrop_source, TransactionType.NONE, int(1e5)))
print(f'submitted: {base58.b58encode(tx_id)}')

tx_data = client.get_transaction(tx_id)
print(repr(tx_data))

# Send a payment of 1 Kin with a text memo
tx_id = submit_payment(Payment(sender, airdrop_source, TransactionType.NONE, int(1e5), memo='somememo'))
print(f'submitted: {base58.b58encode(tx_id)}')

tx_data = client.get_transaction(tx_id)
print(repr(tx_data))

print(f'balance: {client.get_balance(sender.public_key)}')

# Send earn batch
earns = [Earn(airdrop_source, int(1e5)) for i in range(0, 5)]
batch_result = client.submit_earn_batch(sender, earns)
print(f'{len(batch_result.succeeded)} succeeded, {len(batch_result.failed)} failed')
for result in batch_result.succeeded:
    print(f'Sent 1 kin to {result.earn.destination.stellar_address} in transaction '
          f'{base58.b58encode(result.tx_id)}')
for result in batch_result.failed:
    print(f'Failed to send 1 kin to {result.earn.destination.stellar_address} in transaction '
          f'{base58.b58encode(result.tx_id)} (error: {repr(result.error)})')

print(f'balance: {client.get_balance(sender.public_key, commitment=Commitment.ROOT)}')

# The client should be closed once it is no longer needed.
client.close()