Пример #1
0
def create_escrow_account(activationaccountsecret, owneraddress, cosignersfile,
                          fullassetcode):
    splitassetcode = fullassetcode.split(":")
    asset_code = splitassetcode[0]
    asset_issuer = splitassetcode[1]
    activation_kp = Keypair.from_secret(activationaccountsecret)

    horizon_server = stellar_sdk.Server()
    activation_account = horizon_server.load_account(activation_kp.public_key)

    new_escrow_account = create_account()
    escrow_address = new_escrow_account["address"]
    vesting_kp = Keypair.from_secret(new_escrow_account["secret"])
    txb = (TransactionBuilder(
        activation_account,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE
    ).append_create_account_op(escrow_address,
                               starting_balance="7.6").append_change_trust_op(
                                   asset_code,
                                   asset_issuer,
                                   source=escrow_address))
    tx = txb.build()
    tx.sign(activation_kp)
    tx.sign(vesting_kp)
    horizon_server.submit_transaction(tx)
    vesting_account = horizon_server.load_account(escrow_address)
    txb = (TransactionBuilder(
        vesting_account,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE).
           append_ed25519_public_key_signer(owneraddress,
                                            weight=5,
                                            source=escrow_address))
    cosigners = json.load(cosignersfile)
    for cosigner in cosigners:
        txb.append_ed25519_public_key_signer(cosigner["address"],
                                             weight=1,
                                             source=escrow_address)
    txb.append_manage_data_op(DATA_ENTRY_KEY,
                              "here comes the formula or reference",
                              source=escrow_address)

    recovery_transaction = create_recovery_transaction(
        escrow_address, asset_code, asset_issuer, activation_kp.public_key)
    txb.append_pre_auth_tx_signer(recovery_transaction.hash(),
                                  weight=10,
                                  source=escrow_address)

    txb.append_set_options_op(master_weight=0,
                              low_threshold=10,
                              med_threshold=10,
                              high_threshold=10,
                              source=escrow_address)

    tx = txb.build()
    tx.sign(vesting_kp)
    horizon_server.submit_transaction(tx)
    print(f"Created escrow account {escrow_address}")
    print(f"Recovery transaction:\n{recovery_transaction.to_xdr()}")
def create_buy_order(buying_account_secret, amount, network):
    buying_asset_code = "TFT"
    buying_asset_issuer = ASSET_ISSUERS[network][buying_asset_code]
    selling_asset_code = "BTC"
    selling_asset_issuer = ASSET_ISSUERS[network][selling_asset_code]
    price = "0.0000019"

    buying_kp = Keypair.from_secret(buying_account_secret)

    horizon_server = stellar_sdk.Server(_HORIZON_NETWORKS[network])
    source_account = horizon_server.load_account(buying_kp.public_key)
    transaction = (
        stellar_sdk.TransactionBuilder(
            source_account=source_account,
            network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE
            if network == "test"
            else stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE,
            base_fee=0,
        )
        .append_manage_buy_offer_op(
            selling_code=selling_asset_code,
            selling_issuer=selling_asset_issuer,
            buying_code=buying_asset_code,
            buying_issuer=buying_asset_issuer,
            amount=amount,
            price=price,
        )
        .set_timeout(60)
        .build()
    )
    transaction.sign(buying_kp)
    return transaction
Пример #3
0
def createpayment_transaction(destination, asset, amount, network,
                              from_address):
    if from_address == "":
        keypair = Keypair.random()
        from_address = keypair.public_key
        print("Generated sending keypair with secret {}".format(
            keypair.secret))

    split_asset = asset.split(":", 1)
    asset_code = split_asset[0]
    asset_issuer = split_asset[1]

    asset = Asset(code=asset_code, issuer=asset_issuer)
    # Create the transaction

    op = Payment(destination, asset, amount, from_address)
    transaction = Transaction(
        source=stellar_sdk.Keypair.from_public_key(from_address),
        sequence=1,
        fee=0,
        operations=[op])
    transaction_envelope = TransactionEnvelope(
        transaction=transaction,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE if
        network == "test" else stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE,
    )
    print(transaction_envelope.to_xdr())
Пример #4
0
def createpayment_transaction(accountsecret, destination, feedestination, fee,
                              asset, amount, network):

    network_passphrase = (stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE
                          if network == "test" else
                          stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE)
    horizon_server = stellar_sdk.Server(
        "https://horizon-testnet.stellar.org" if network ==
        "test" else "https://horizon.stellar.org")

    keypair = Keypair.from_secret(accountsecret)
    from_address = keypair.public_key

    split_asset = asset.split(":", 1)
    asset_code = split_asset[0]
    asset_issuer = split_asset[1]

    source_account = horizon_server.load_account(from_address)
    txe = (stellar_sdk.TransactionBuilder(
        source_account=source_account,
        network_passphrase=network_passphrase,
        base_fee=0).append_payment_op(
            destination,
            amount,
            asset_code=asset_code,
            asset_issuer=asset_issuer).append_payment_op(
                feedestination,
                fee,
                asset_code=asset_code,
                asset_issuer=asset_issuer).set_timeout(60 * 3).build())

    txe.sign(keypair)
    print(txe.to_xdr())
def fee_bump(funding_account_secret, buy_transaction: stellar_sdk.TransactionEnvelope, network):
    funding_kp = Keypair.from_secret(funding_account_secret)

    horizon_server = stellar_sdk.Server(_HORIZON_NETWORKS[network])
    base_fee = horizon_server.fetch_base_fee()
    fb_txe = stellar_sdk.TransactionBuilder.build_fee_bump_transaction(
        fee_source=funding_kp.public_key,
        base_fee=base_fee,
        inner_transaction_envelope=buy_transaction,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE
        if network == "test"
        else stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE,
    )
    fb_txe.sign(funding_kp)
    response = horizon_server.submit_transaction(fb_txe)
    print(f"Submittted fee bumped transaction {response['hash']}")
Пример #6
0
def end_sponsorship(activatorsecret, sponsoredaccount):
    activator_kp = Keypair.from_secret(activatorsecret)

    horizon_server = stellar_sdk.Server()

    source_account = horizon_server.load_account(activator_kp.public_key)

    base_fee = horizon_server.fetch_base_fee()
    transaction = (stellar_sdk.TransactionBuilder(
        source_account=source_account,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE,
        base_fee=base_fee,
    ).append_revoke_account_sponsorship_op(sponsoredaccount).build())
    transaction.sign(activator_kp)
    horizon_server.submit_transaction(transaction)
    print(f"Stopped sponsoring account {sponsoredaccount }")
def create_account(activatorsecret, fullassetcode):
    activator_kp = Keypair.from_secret(activatorsecret)
    keypair = Keypair.random()
    address = keypair.public_key
    activate_account(activator_kp, keypair, fullassetcode)
    print(f"Activated account {address } with secret {keypair.secret}")
def create_account() -> map:
    keypair = Keypair.random()
    return {"address": keypair.public_key, "secret": keypair.secret}
def create_account():
    keypair = Keypair.random()
    address = keypair.public_key
    print(f"Generated account {address } with secret {keypair.secret}")
    activate_through_friendbot(address)
    print(f"Account activated through friendbot")