def test_from_string(self): address = "GCABWU4FHL3RGOIWCX5TOVLIAMLEU2YXXLCMHVXLDOFHKLNLGCSBRJYP" seed = "SCZ4KGTCMAFIJQCCJDMMKDFUB7NYV56VBNEU7BKMR4PQFUETJCWLV6GN" pub = PublicKey.from_string(address) assert pub.stellar_address == address priv = PrivateKey.from_string(seed) assert priv.stellar_seed == seed # Test invalid cases with pytest.raises(ValueError): PublicKey.from_string('invalidlength') with pytest.raises(ValueError): PublicKey.from_string(seed) # not an address with pytest.raises(ValueError): PrivateKey.from_string('invalidlength') with pytest.raises(ValueError): PrivateKey.from_string(address) # not a seed
ap.add_argument('-s', '--sender', required=True, help='The private seed of the sender account') ap.add_argument( '-d', '--destinations', required=True, help= '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()}'
import argparse from agora.client import Client, RetryConfig, Environment from agora.error import AccountExistsError from agora.keys import PrivateKey ap = argparse.ArgumentParser() ap.add_argument('-s', '--seed', required=True, help='The private seed of the account to create') args = vars(ap.parse_args()) client = Client(Environment.TEST, 1) # 1 is the test app index private_key = PrivateKey.from_string(args['seed']) print( f'creating account with address {private_key.public_key.stellar_address}') try: client.create_account(private_key) print('account created') except AccountExistsError: print(f'account {private_key.public_key.stellar_address} already exists') client.close()
from flask import Flask, request from agora.client import Environment from agora.error import InvoiceErrorReason from agora.keys import PrivateKey from agora.webhook.events import Event from agora.webhook.handler import WebhookHandler, AGORA_HMAC_HEADER, APP_USER_ID_HEADER, APP_USER_PASSKEY_HEADER from agora.webhook.sign_transaction import SignTransactionRequest, SignTransactionResponse logging.basicConfig(level=logging.DEBUG) app = Flask(__name__) webhook_secret = os.environ.get("WEBHOOK_SECRET") webhook_seed = os.environ.get("WEBHOOK_SEED") webhook_private_key = PrivateKey.from_string(webhook_seed) webhook_handler = WebhookHandler(Environment.TEST, webhook_secret) @app.route('/events', methods=['POST']) def events(): status_code, body = webhook_handler.handle_events( _handle_events, request.headers.get(AGORA_HMAC_HEADER), request.data.decode('utf-8'), ) return body, status_code @app.route('/sign_transaction', methods=["POST"])