def gen_account_id_from_address(address: str) -> xdr_type.AccountID: public_key = PublicKey.from_string(address) return xdr_type.AccountID( type=xdr_const.PUBLIC_KEY_TYPE_ED25519, ed25519=public_key.raw, )
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
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()}' ) for result in batch_result.failed:
def payments_from_envelope( cls, envelope: te.TransactionEnvelope, invoice_list: Optional[model_pb2.InvoiceList] = None, kin_version: Optional[int] = 3, ) -> List['ReadOnlyPayment']: """Returns a list of read only payments from a transaction envelope. :param envelope: A :class:`TransactionEnvelope <kin_base.transaction_envelope.TransactionEnvelope>. :param invoice_list: (optional) A protobuf invoice list associated with the transaction. :param kin_version: (optional) The version of Kin to parse payments for. :return: A List of :class:`ReadOnlyPayment <ReadOnlyPayment>` objects. """ if invoice_list and invoice_list.invoices and len( invoice_list.invoices) != len(envelope.tx.operations): raise ValueError( f'number of invoices ({len(invoice_list.invoices)}) does not match number of transaction ' f'operations ({len(envelope.tx.operations)})') tx = envelope.tx text_memo = None agora_memo = None if isinstance(tx.memo, memo.HashMemo): try: agora_memo = AgoraMemo.from_base_memo(tx.memo, False) except ValueError: pass elif isinstance(tx.memo, memo.TextMemo): text_memo = tx.memo payments = [] for idx, op in enumerate(envelope.tx.operations): # Currently, only payment operations are supported in this method. Eventually, create account and merge # account operations could potentially be supported, but currently this is primarily only used for payment # operations if not isinstance(op, operation.Payment): continue # Only Kin payment operations are supported in this method. if kin_version == 2 and (op.asset.type != 'credit_alphanum4' or op.asset.code != 'KIN'): continue inv = invoice_list.invoices[ idx] if invoice_list and invoice_list.invoices else None # Inside the kin_base module, the base currency has been 'scaled' by a factor of 100 from # Stellar (i.e., the smallest denomination used is 1e-5 instead of 1e-7). However, Kin 2 uses the minimum # Stellar denomination of 1e-7. # # When parsing an XDR transaction, `kin_base` assumes a smallest denomination of 1e-5. Therefore, for Kin 2 # transactions, we must divide the resulting amounts by 100 to account for the 100x scaling factor. payments.append( ReadOnlyPayment( sender=PublicKey.from_string( op.source if op.source else tx.source.decode()), destination=PublicKey.from_string(op.destination), tx_type=agora_memo.tx_type() if agora_memo else TransactionType.UNKNOWN, quarks=int(kin_to_quarks(op.amount) / 100) if kin_version == 2 else kin_to_quarks(op.amount), invoice=Invoice.from_proto(inv) if inv else None, memo=text_memo.text.decode() if text_memo else None, )) return payments
print(f'transaction failed: {repr(e)}') if isinstance(e, TransactionErrors): print(f'tx_error={repr(e.tx_error)}, len(op_errors)={len(e.op_errors)}') for op_error in e.op_errors: print(f'op_error={repr(op_error)}') ap = argparse.ArgumentParser() ap.add_argument('-s', '--sender', required=True, help='The private seed of the sender account') ap.add_argument('-d', '--destination', required=True, help='The public address of the destination account') args = vars(ap.parse_args()) client = Client(Environment.TEST, 1) # 1 is the test app index source = PrivateKey.from_string(args['sender']) dest = PublicKey.from_string(args['destination']) # Send a payment of 1 Kin payment = Payment(source, dest, TransactionType.EARN, kin_to_quarks('1')) submit_payment(payment) # Send a payment of 1 Kin with a text memo payment = Payment(source, dest, TransactionType.EARN, kin_to_quarks('1'), memo='1-test') submit_payment(payment) # Send payment of 1 Kin with an invoice invoice = Invoice([LineItem('Test Payment', 100000, description='This is a description of the payment', sku=b'some sku')]) payment = Payment(source, dest, TransactionType.EARN, kin_to_quarks('1'), invoice=invoice)