def generateTransaction(balance, balances, id): # Check if asset is trusted print(balances) establish_trustline = verifyItExists(balance.get('asset'), balances) print(balance) if NETWORK == "TESTNET": passphrase = Network.TESTNET_NETWORK_PASSPHRASE else: passphrase = Network.PUBLIC_NETWORK_PASSPHRASE account = server.load_account(balance['claimants'][0]['destination']) base_fee = server.fetch_base_fee() if establish_trustline: transaction = TransactionBuilder( source_account=account, network_passphrase=passphrase).append_claim_claimable_balance_op( balance_id=id, ).build() else: asset = Asset(asset_name, asset_issuer) transaction = TransactionBuilder( source_account=account, network_passphrase=passphrase).append_change_trust_op( asset_code=asset, asset_issuer=asset_issuer).append_claim_claimable_balance_op( balance_id=id, source=user_pub_key).build() print(transaction.to_xdr()) return transaction.to_xdr()
def remove_signer(self, public_key_signer): """remove_signer removes a public key as a signer from the source account :param public_key_signer: public key of an account :type public_key_signer: str """ account = self.load_account() horizon_server = self._get_horizon_server() base_fee = horizon_server.fetch_base_fee() tx = TransactionBuilder( account, network_passphrase=_NETWORK_PASSPHRASES[str(self.network)], base_fee=base_fee).append_ed25519_public_key_signer( public_key_signer, 0).build() source_keypair = Keypair.from_secret(self.secret) tx.sign(source_keypair) try: response = horizon_server.submit_transaction(tx) self._log_info(response) self._log_info("Multisig tx signed and sent") except BadRequestError: self._log_info( "Transaction need additional signatures in order to send") return tx.to_xdr()
def merge_account(self, address): """ Delete the wallet and send all funds to the specified address :param address: address to send funds to :return: tx hash """ self.check_and_update_created_on_network() if not self.created_on_network: return fail( RuntimeError( 'Cannot do account merge operation: account is not created on network' )) self._logger.info( 'Deleting wallet and sending all funds to address %s', address) network = Network.PUBLIC_NETWORK_PASSPHRASE if not self.testnet else Network.TESTNET_NETWORK_PASSPHRASE tx = TransactionBuilder( source_account=self.account, base_fee=self.provider.get_base_fee(), network_passphrase=network, ).append_account_merge_op(address).build() tx.sign(self.keypair) xdr_tx_envelope = tx.to_xdr() tx_hash = self.provider.submit_transaction(xdr_tx_envelope) self.created_on_network = False return succeed(tx_hash)