Ejemplo n.º 1
0
def set_home_domain(tokencode, home_domain, issuer_secret, network):
    try:
        issuer_keypair = stellar_sdk.Keypair.from_secret(issuer_secret)
    except Ed25519SecretSeedInvalidError:
        raise click.BadOptionUsage('--issuer_secret', 'Invalid issuer secret')
    issuer_address = issuer_keypair.public_key

    print(
        'Setting the homedomain for {tokencode}:{issuer} to {homedomain} on the {network} network'
        .format(tokencode=tokencode,
                issuer=issuer_address,
                homedomain=home_domain,
                network=network))
    horizon_server = stellar_sdk.Server(
    ) if network == 'test' else stellar_sdk.Server(PUBLIC_HORIZON_SERVER)
    base_fee = horizon_server.fetch_base_fee()
    issuer_account = horizon_server.load_account(issuer_address)
    transaction = stellar_sdk.transaction_builder.TransactionBuilder(
        issuer_account,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE if
        network == 'test' else stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE,
        base_fee=base_fee).append_set_options_op(
            home_domain=home_domain).build()
    transaction.sign(issuer_keypair)
    response = horizon_server.submit_transaction(transaction)
    print(response)
Ejemplo n.º 2
0
def add_tft_trustline(source_kp, network):
    horizon_server = stellar_sdk.Server(
    ) if network == "test" else stellar_sdk.Server(PUBLIC_HORIZON_SERVER)
    base_fee = horizon_server.fetch_base_fee()
    source_account = horizon_server.load_account(source_kp.public_key)
    transaction = (stellar_sdk.transaction_builder.TransactionBuilder(
        source_account,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE if
        network == "test" else stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE,
        base_fee=base_fee,
    ).append_change_trust_op("TFT", TFT_ISSUERS[network]).build())
    transaction.sign(source_kp)
    horizon_server.submit_transaction(transaction)
Ejemplo n.º 3
0
def activate_account(address, activator_secret, network):
    activator_keypair = stellar_sdk.Keypair.from_secret(activator_secret)
    horizon_server = stellar_sdk.Server(
    ) if network == "test" else stellar_sdk.Server(PUBLIC_HORIZON_SERVER)
    base_fee = horizon_server.fetch_base_fee()
    activator_account = horizon_server.load_account(
        activator_keypair.public_key)
    transaction = (stellar_sdk.transaction_builder.TransactionBuilder(
        activator_account,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE if
        network == "test" else stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE,
        base_fee=base_fee,
    ).append_create_account_op(address, "5").build())
    transaction.sign(activator_keypair)
    horizon_server.submit_transaction(transaction)
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
Ejemplo n.º 5
0
def send_locked_funds(from_secret, destination, asset, amount):
    from_kp = stellar_sdk.Keypair.from_secret(from_secret)
    split_asset = asset.split(":", 1)
    asset_code = split_asset[0]
    asset_issuer = split_asset[1]
    print(
        "Sending {amount} {asset} from {from_address} to {destination}".format(
            amount=amount,
            asset=asset,
            from_address=from_kp.public_key,
            destination=destination))

    print("Creating  escrow account")
    escrow_kp = create_keypair()
    # minimum account balance as described at https://www.stellar.org/developers/guides/concepts/fees.html#minimum-account-balance
    horizon_server = stellar_sdk.Server()
    base_fee = horizon_server.fetch_base_fee()
    base_reserve = 0.5
    minimum_account_balance = (2 + 1 +
                               3) * base_reserve  # 1 trustline and 3 signers
    required_XLM = minimum_account_balance + base_fee * 0.0000001 * 3
    activate_account(escrow_kp.public_key, from_kp, math.ceil(required_XLM))
    add_trustline(escrow_kp.secret, asset_code, asset_issuer)

    preauth_tx = create_preauth_transaction(escrow_kp)
    preauth_tx_hash = preauth_tx.hash()

    set_account_signers(escrow_kp.public_key, destination, preauth_tx_hash,
                        escrow_kp)
    print("Unlock Transaction:")
    print(preauth_tx.to_xdr())

    send_asset_to_account(escrow_kp.public_key, asset, amount,
                          from_kp.public_key, (from_secret, ))
def verify(activationaccount,network):
    horizon_server=stellar_sdk.Server("https://horizon-testnet.stellar.org" if network=="test" else "https://horizon.stellar.org")
    accounts_endpoint=horizon_server.operations().for_account(activationaccount)
    accounts_endpoint.limit(50)
    old_cursor = "old"
    new_cursor = ""

    number_of_vesting_accounts=0
    vesting_accounts={}
    invalid_vesting_accounts=[]
    while new_cursor != old_cursor:
        old_cursor = new_cursor
        accounts_endpoint.cursor(new_cursor)
        response = accounts_endpoint.call()
        next_link = response["_links"]["next"]["href"]
        next_link_query = parse.urlsplit(next_link).query
        new_cursor = parse.parse_qs(next_link_query, keep_blank_values=True)["cursor"][0]
        for operation in response["_embedded"]["records"]:
            if operation["type"]!="create_account" or operation["source_account"]!=activationaccount:
                continue
            vesting_account_id=operation["account"]
            owner_account_id=get_owner_address(horizon_server,vesting_account_id)
            if not owner_account_id:
                invalid_vesting_accounts.append(vesting_account_id)
                continue
            print(f"Created vesting account {vesting_account_id} for owner {owner_account_id}")
            number_of_vesting_accounts+=1
            accounts_for_owner=vesting_accounts.get(owner_account_id,[])
            accounts_for_owner.append(vesting_account_id)
            vesting_accounts[owner_account_id]=accounts_for_owner
    print(f"{number_of_vesting_accounts} vesting accounts have been created for {len(vesting_accounts.keys())} owner accounts")
    if len(invalid_vesting_accounts)>0:
        print("Invalid vesting accounts:")
        print("\n".join(invalid_vesting_accounts))
Ejemplo n.º 7
0
def list_issued():
    horizon_server = stellar_sdk.Server("https://horizon.stellar.org")
    tx_endpoint = horizon_server.transactions()
    tx_endpoint.limit = 50
    for tokencode, issuer in ISSUERS.items():
        tx_endpoint.for_account(issuer)
        tx_endpoint.include_failed(False)
        old_cursor = "old"
        new_cursor = ""
        while old_cursor != new_cursor:
            old_cursor = new_cursor
            tx_endpoint.cursor(new_cursor)
            response = tx_endpoint.call()
            next_link = response["_links"]["next"]["href"]
            next_link_query = parse.urlsplit(next_link).query
            new_cursor = parse.parse_qs(next_link_query)["cursor"][0]
            response_transactions = response["_embedded"]["records"]
            for response_transaction in response_transactions:
                if response_transaction["memo_type"] != "hash":
                    continue
                memo = binascii.hexlify(base64.b64decode(response_transaction["memo"])).decode("utf-8")
                env = stellar_sdk.transaction_envelope.TransactionEnvelope.from_xdr(
                    response_transaction["envelope_xdr"], stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE
                )
                paymentoperation = env.transaction.operations[0]

                print(
                    f"{memo} {paymentoperation.amount} {tokencode} {paymentoperation.destination} {response_transaction['id']}"
                )
def activate_account(source_keypair, new_account_kp, fullassetcode):
    split_asset = fullassetcode.split(":", 1)
    asset_code = split_asset[0]
    asset_issuer = split_asset[1]
    new_account_address = new_account_kp.public_key

    horizon_server = stellar_sdk.Server()

    source_account = horizon_server.load_account(source_keypair.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_begin_sponsoring_future_reserves_op(
        new_account_address).append_create_account_op(
            destination=new_account_address,
            starting_balance="0").append_change_trust_op(
                asset_issuer=asset_issuer,
                asset_code=asset_code,
                source=new_account_address).
                   append_end_sponsoring_future_reserves_op(
                       new_account_address).set_timeout(60).build())
    transaction.sign(source_keypair)
    transaction.sign(new_account_kp)
    horizon_server.submit_transaction(transaction)
Ejemplo n.º 9
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())
Ejemplo n.º 10
0
def send_asset_to_account(destination, asset, amount, from_secret,
                          funder_secret):
    split_asset = asset.split(':', 1)
    asset_code = split_asset[0]
    asset_issuer = split_asset[1]
    #Create keypairs from the secrets
    from_kp = stellar_sdk.Keypair.from_secret(from_secret)
    funder_kp = stellar_sdk.Keypair.from_secret(funder_secret)

    #load the funder account
    horizon_server = stellar_sdk.Server()
    funder_account = horizon_server.load_account(funder_kp.public_key)

    # Create the transaction
    transaction = TransactionBuilder(funder_account).append_payment_op(
        destination,
        amount,
        asset_code,
        asset_issuer,
        source=from_kp.public_key).build()
    transaction.sign(from_kp)
    transaction.sign(funder_kp)
    response = horizon_server.submit_transaction(transaction)
    print(response)
    print(
        'Sent {amount} {asset} from {from_address} to {destination} funded by {funder_address}'
        .format(amount=amount,
                asset=asset,
                from_address=from_kp.public_key,
                destination=destination,
                funder_address=funder_kp.public_key))
Ejemplo n.º 11
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()}")
Ejemplo n.º 12
0
def create_preauth_transaction(escrow_kp):
    unlock_time = int(time.time()) + 60 * 10  # 10 minutes from now
    horizon_server = stellar_sdk.Server()
    escrow_account = horizon_server.load_account(escrow_kp.public_key)
    escrow_account.increment_sequence_number()
    tx = (TransactionBuilder(escrow_account).append_set_options_op(
        master_weight=0, low_threshold=1, med_threshold=1,
        high_threshold=1).add_time_bounds(unlock_time, 0).build())
    tx.sign(escrow_kp)
    return tx
Ejemplo n.º 13
0
def set_home_domain(tokencode, home_domain, issuer_secret, network):
    try:
        issuer_keypair = stellar_sdk.Keypair.from_secret(issuer_secret)
    except Ed25519SecretSeedInvalidError:
        raise click.BadOptionUsage("--issuer_secret", "Invalid issuer secret")
    issuer_address = issuer_keypair.public_key

    horizon_server = stellar_sdk.Server(
    ) if network == "test" else stellar_sdk.Server(PUBLIC_HORIZON_SERVER)
    base_fee = horizon_server.fetch_base_fee()
    issuer_account = horizon_server.load_account(issuer_address)
    transaction = (stellar_sdk.transaction_builder.TransactionBuilder(
        issuer_account,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE if
        network == "test" else stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE,
        base_fee=base_fee,
    ).append_set_options_op(home_domain=home_domain).build())
    transaction.sign(issuer_keypair)
    horizon_server.submit_transaction(transaction)
Ejemplo n.º 14
0
def sign_and_submit(transaction, secret):
    # Create keypairs from the secrets
    kp = stellar_sdk.Keypair.from_secret(secret)

    horizon_server = stellar_sdk.Server()

    txe = stellar_sdk.TransactionEnvelope.from_xdr(
        transaction, stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE)
    txe.sign(kp)
    response = horizon_server.submit_transaction(txe)
    print(response)
Ejemplo n.º 15
0
def add_trustline(secret_key, asset_code, asset_issuer):
    kp = stellar_sdk.Keypair.from_secret(secret_key)
    horizon_server = stellar_sdk.Server()
    account = horizon_server.load_account(kp.public_key)
    transaction = TransactionBuilder(account).append_change_trust_op(asset_code, asset_issuer).build()
    transaction.sign(kp)
    response = horizon_server.submit_transaction(transaction)
    print(response)
    print(
        "Added trustline to {asset_code}:{asset_issuer} for account {address}".format(
            asset_code=asset_code, asset_issuer=asset_issuer, address=kp.public_key
        )
    )
Ejemplo n.º 16
0
def monitor(activationaccount, network):
    horizon_server = stellar_sdk.Server(
        "https://horizon-testnet.stellar.org" if network == "test" else "https://horizon.stellar.org"
    )
    accounts_endpoint = horizon_server.accounts().account_id(activationaccount)

    response = accounts_endpoint.call()
    xlm_balance = [float(balance["balance"]) for balance in response["balances"] if balance["asset_type"] == "native"][
        0
    ]

    sponsored_balance = response["num_sponsoring"] * 0.5
    print(f"{activationaccount} holds {xlm_balance} XLM of which {xlm_balance-sponsored_balance} is free")
Ejemplo n.º 17
0
def send_asset_to_account(destination, asset, amount, source, signer):
    split_asset = asset.split(':', 1)
    asset_code = split_asset[0]
    asset_issuer = split_asset[1]
    horizon_server = stellar_sdk.Server()
    source_account = horizon_server.load_account(source)
    transaction = TransactionBuilder(source_account).append_payment_op(
        destination, amount, asset_code, asset_issuer).build()
    for sk in signer:
        kp = stellar_sdk.Keypair.from_secret(sk)
        transaction.sign(kp)
    response = horizon_server.submit_transaction(transaction)
    print(response)
    print('Sent {amount} {asset} to {destination}'.format(
        amount=amount, asset=asset, destination=destination))
Ejemplo n.º 18
0
def add_trustline(
    accountsecret: str,
    fullassetcode:
    str = "TFT:GA47YZA3PKFUZMPLQ3B5F2E3CJIB57TGGU7SPCQT2WAEYKN766PWIMB3"):
    splitassetcode = fullassetcode.split(":")
    # Create keypair from the secret
    kp = stellar_sdk.Keypair.from_secret(accountsecret)

    horizon_server = stellar_sdk.Server()
    account = horizon_server.load_account(kp.public_key)
    txbuilder = TransactionBuilder(account)
    txbuilder.append_change_trust_op(splitassetcode[0], splitassetcode[1])
    txe = txbuilder.build()
    txe.sign(kp)
    horizon_server.submit_transaction(txe)
Ejemplo n.º 19
0
def transfer(accountsecret, fullassetcode, destination, amount):

    split_asset = fullassetcode.split(":", 1)
    asset_code = split_asset[0]
    asset_issuer = split_asset[1]
    # Create keypair from the secret
    kp = stellar_sdk.Keypair.from_secret(accountsecret)

    horizon_server = stellar_sdk.Server()
    account = horizon_server.load_account(kp.public_key)
    txbuilder = TransactionBuilder(account)
    txbuilder.append_payment_op(destination, amount, asset_code, asset_issuer)
    txe = txbuilder.build()
    txe.sign(kp)
    horizon_server.submit_transaction(txe)
Ejemplo n.º 20
0
def create_recovery_transaction(
        vesting_address, asset_code: str, asset_issuer: str,
        activation_account: str) -> stellar_sdk.TransactionEnvelope:

    horizon_server = stellar_sdk.Server()
    source_account = horizon_server.load_account(vesting_address)
    source_account.sequence += 1
    txe = (TransactionBuilder(
        source_account,
        network_passphrase=stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE).
           append_change_trust_op(
               asset_code=asset_code,
               asset_issuer=asset_issuer, limit="0").append_manage_data_op(
                   DATA_ENTRY_KEY,
                   None).append_account_merge_op(activation_account).build())
    return txe
Ejemplo n.º 21
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 }")
Ejemplo n.º 22
0
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']}")
Ejemplo n.º 23
0
def find_escrow_accounts(receiver, asset):
    stellar_asset = asset_from_full_string(asset)
    horizon_server = stellar_sdk.Server()
    accounts_endpoint = horizon_server.accounts()
    accounts_endpoint.signer(receiver)
    old_cursor = "old"
    new_cursor = ""
    while new_cursor != old_cursor:
        old_cursor = new_cursor
        accounts_endpoint.cursor(new_cursor)
        response = accounts_endpoint.call()
        next_link = response["_links"]["next"]["href"]
        next_link_query = parse.urlsplit(next_link).query
        new_cursor = parse.parse_qs(next_link_query)["cursor"][0]
        accounts = response["_embedded"]["records"]
        for account in accounts:
            account_id = account["account_id"]
            if account_id == receiver:
                continue  # Do not take the receiver's account
            balances = account["balances"]
            asset_balances = [
                balance for balance in balances
                if balance["asset_type"] == stellar_asset.guess_asset_type()
                and balance["asset_code"] == stellar_asset.code
                and balance["asset_issuer"] == stellar_asset.issuer
            ]
            asset_balance = decimal.Decimal(0)
            for balance in asset_balances:
                asset_balance += decimal.Decimal(balance["balance"])
            if asset_balance == decimal.Decimal():
                continue  # 0 so skip

            all_signers = account["signers"]
            preauth_signers = [
                signer["key"] for signer in all_signers
                if signer["type"] == "preauth_tx"
            ]
            # TODO check the tresholds and signers
            # TODO if we can merge, the amount is unlocked ( if len(preauth_signers))==0
            print(
                "Account {account} with {asset_balance} {asset_code} has unlocktransaction hashes {unlockhashes}"
                .format(
                    account=account_id,
                    asset_balance=asset_balance,
                    asset_code=stellar_asset.code,
                    unlockhashes=preauth_signers,
                ))
Ejemplo n.º 24
0
def get_escrowaccount_unlocktime(address):
    horizon_server = stellar_sdk.Server("https://horizon.stellar.org")
    accounts_endpoint = horizon_server.accounts()
    accounts_endpoint.account_id(address)
    response = accounts_endpoint.call()
    preauth_signer = [signer["key"] for signer in response["signers"] if signer["type"] == "preauth_tx"][0]
    resp = requests.post(
        "https://tokenservices.threefold.io/threefoldfoundation/unlock_service/get_unlockhash_transaction",
        json={"args": {"unlockhash": preauth_signer}},
    )
    resp.raise_for_status()

    txe = stellar_sdk.TransactionEnvelope.from_xdr(
        resp.json()["transaction_xdr"], stellar_sdk.Network.PUBLIC_NETWORK_PASSPHRASE
    )
    tx = txe.transaction
    if tx.time_bounds is not None:
        return tx.time_bounds.min_time
def export(network):

    issuances = []
    horizon_server = stellar_sdk.Server(_HORIZON_NETWORKS[network])
    for token in ("TFT", "TFTA"):
        issuer = _ASSET_ISUERS[network][token]
        endpoint = horizon_server.operations().for_account(issuer)
        endpoint.limit(100)
        old_cursor = "old"
        new_cursor = ""
        while new_cursor != old_cursor:
            old_cursor = new_cursor
            endpoint.cursor(new_cursor)
            response = endpoint.call()
            next_link = response["_links"]["next"]["href"]
            next_link_query = parse.urlsplit(next_link).query
            new_cursor = parse.parse_qs(next_link_query, keep_blank_values=True)["cursor"][0]
            for operation in response["_embedded"]["records"]:
                if ("asset_code" not in operation) or operation["asset_code"] != token:
                    continue
                amount = float(operation["amount"])
                if operation["to"] == issuer:
                    amount *= -1
                issued_at = dateutil.parser.parse(operation["created_at"])
                issuances.append({"token": token, "amount": amount, "issued_at": issued_at})

    def sort_key(a):
        return a["issued_at"]

    issuances.sort(key=sort_key)
    total_tft = 0.0
    total_tfta = 0.0
    for issuance in issuances:
        amount_tft = 0
        amount_tfta = 0
        if issuance["token"] == "TFT":
            amount_tft = issuance["amount"]
            total_tft += amount_tft
        else:
            amount_tfta = issuance["amount"]
            total_tfta += amount_tfta
        print(
            f"{issuance['issued_at']:%Y/%m/%d},{amount_tft},{amount_tfta},{total_tft},{total_tfta},{total_tft+total_tfta}"
        )
Ejemplo n.º 26
0
def set_account_signers(address, public_key_signer, preauth_tx_hash,
                        signer_kp):
    horizon_server = stellar_sdk.Server()
    account = horizon_server.load_account(address)
    tx = (TransactionBuilder(account).append_pre_auth_tx_signer(
        preauth_tx_hash, 1).append_ed25519_public_key_signer(
            public_key_signer,
            1).append_set_options_op(master_weight=1,
                                     low_threshold=2,
                                     med_threshold=2,
                                     high_threshold=2).build())

    tx.sign(signer_kp)
    response = horizon_server.submit_transaction(tx)
    print(response)
    print(
        "Set the signers of {address} to {pk_signer} and {preauth_hash_signer}"
        .format(address=address,
                pk_signer=public_key_signer,
                preauth_hash_signer=preauth_tx_hash))
Ejemplo n.º 27
0
def validate(transaction_hash, network):
    horizon_server = stellar_sdk.Server(_HORIZON_NETWORKS[network])
    tokendestructions = []
    issuer = _ASSET_ISUERS[network]["TFTA"]
    try:
        response = horizon_server.payments().for_transaction(transaction_hash).limit(100).call()
        payments = response["_embedded"]["records"]
        for payment in payments:
            if payment["to"] != _ASSET_ISUERS[network]["TFTA"]:
                continue
            if payment["type"] != "payment":
                continue
            if payment["asset_type"] == "native":
                continue
            if payment["asset_code"] != "TFTA" or payment["asset_issuer"] != issuer:
                continue
            amount = payment["amount"]
            sender = payment["from"]
            tokendestructions.append(TokenDestruction("TFTA", issuer, amount, sender))
    except stellar_sdk.exceptions.BadRequestError as e:
        if not "invalid_field" in e.extras:
            raise e
    return tokendestructions
Ejemplo n.º 28
0
def update_foundation_wallets_data():
    redis = j.clients.redis.get("redis_instance")
    foundation_wallets = _get_foundation_wallets()
    horizon_server = stellar_sdk.Server("https://horizon.stellar.org")
    for category in foundation_wallets:
        for foundation_wallet in category["wallets"]:
            endpoint = horizon_server.accounts().account_id(
                foundation_wallet["address"])
            account_data = endpoint.call()
            tftbalances = [
                balance["balance"] for balance in account_data["balances"]
                if balance.get("asset_code") == "TFT"
                and balance.get("asset_issuer") == TFT_ISSUER
            ]
            foundation_wallet["TFT"] = tftbalances[0] if tftbalances else "0.0"
            foundation_wallet["signers"] = [
                signer["key"] for signer in account_data["signers"]
            ]
            required_signatures = account_data["thresholds"]["med_threshold"]
            foundation_wallet[
                "required_signatures"] = required_signatures if required_signatures != 0 else 1
    res = j.data.serializers.json.dumps(foundation_wallets)
    redis.set(f"foundationaccounts-detailed", res)
    return res
Ejemplo n.º 29
0
def _get_horizon_server(network: str):
    server_url = _HORIZON_NETWORKS[network]
    return stellar_sdk.Server(horizon_url=server_url)
Ejemplo n.º 30
0
    def _get_horizon_server(self):

        return stellar_sdk.Server(horizon_url=_HORIZON_NETWORKS[self._get_network()])