def main(): client = ark.ArkClient('http://localhost:4003/api') # this imports transfer from crypto.transactions.builder.transfer import Transfer from crypto.identity.address import address_from_passphrase from crypto.identity.private_key import PrivateKey from crypto.identity.public_key import PublicKey from crypto.identity.address import address_from_private_key # print(a) # delegates = client.delegates.all() # print(client.blocks.all()) # print(delegates) # unique id that each recipient has # result = # print(result) # wallet = client.wallets # happens in recipients computer # recipientSecret = randomPhrase() # recipientSecret = "trade dog shed today law swear icon destroy goat more select praise" # priv = PrivateKey.from_passphrase(recipientSecret).to_hex() # print(priv) # address = address_from_private_key(priv, network_version=23) # print(address) # address = "AUXmEForVfTHqQHyVta1gyWo4BJ4hsm71k" address = "AJsumLTKPqzq1mcpvogMt59DvbYmad44EV" senderSecret = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire" # priv = PrivateKey.from_passphrase(senderSecret).to_hex() # print(priv) # adr = address_from_private_key(priv, network_version=23) # print(adr) tx = Transfer(recipientId=address, amount=50000000) tx.sign(senderSecret) # print(tx.to_dict()) # print("\n") ok = client.transactions.create([tx.transaction.to_dict()]) pprint(ok)
def main(): passphrase = sys.argv[1:0] vote = sys.argv[1:1] from crypto.transactions.builder.transfer import Transfer from crypto.identity.address import address_from_private_key from crypto.identity.private_key import PrivateKey from crypto.identity.public_key import PublicKey from crypto.identity.address import address_from_private_key import time from crypto.configuration.network import set_custom_network from crypto.transactions.builder.transfer import Transfer # from tbw import parse_config # from util.sql import SnekDB # from util.dynamic import Dynamic from ark import ArkClient client = ArkClient('http://localhost:4003/api') from datetime import datetime epoch = datetime(2017, 1, 1, 13, 00, 00) version = 23 wif = 130 work = set_custom_network(epoch, version, wif) # userInput # passPhrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire" phrase = "outside tilt cluster film husband truck install fringe purse door build wire" candidate = "ANBkoGqWeTSiaEVgVzSKZd3jS7UWzv9PSo" # chooseVoter("Donald Trump") print(candidate) # priv = PrivateKey.from_passphrase(candidate).to_hex() tx = Transfer(recipientId=candidate, amount=50000) tx.sign(phrase) # print(tx.verify()) ok = client.transactions.create([tx.transaction.to_dict()]) pprint(ok) print(passphrase) print(vote)
def test_parse_signatures(transaction_type_0): """Test if parse signature works when parsing serialized data """ transfer = Transfer(recipientId=transaction_type_0['recipientId'], amount=transaction_type_0['amount']) assert transfer.transaction.signature is None transfer.transaction.parse_signatures(transaction_type_0['serialized'], 166) assert transfer.transaction.signature
def build_transfer_transaction(address, amount, vendor, fee, pp, sp, nonce): # python3 crypto version transaction = Transfer(recipientId=address, amount=amount, vendorField=vendor, fee=fee) transaction.set_nonce(int(nonce)) transaction.schnorr_sign(pp) if sp == 'None': sp = None if sp is not None: transaction.second_sign(sp) transaction_dict = transaction.to_dict() return transaction_dict
def build_transfer_transaction(address, amount, vendor, fee, pp, sp): transaction = Transfer(recipientId=address, amount=amount, vendorField=vendor, fee=fee) transaction.sign(pp) if sp is not None: transaction.second_sign(sp) transaction_dict = transaction.to_dict() return transaction_dict
def test_transfer_transaction(): """Test if a transfer transaction gets built """ transaction = Transfer(recipientId='AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25', amount=1000, vendorField='Hello Pythonistas!') transaction.sign('This is a top secret passphrase') transaction_dict = transaction.to_dict() assert transaction_dict['signature'] assert transaction_dict['type'] is TRANSACTION_TRANSFER transaction.verify( ) # if no exception is raised, it means the transaction is valid
def build_transfer_transaction(address, amount, vendor, pp, sp, nonce): # python3 crypto version if data.network == "nos_realdevnet" or data.network == "compendia_realmainnet": transaction = Transfer(recipientId=address, amount=amount, fee=10000000) else: fee = dynamic.get_dynamic_fee(vendor, sp != None) transaction = Transfer(recipientId=address, amount=amount, vendorField=vendor, fee=fee) transaction.set_nonce(int(nonce)) transaction.schnorr_sign(pp) if sp == 'None': sp = None if sp is not None: transaction.second_sign(sp) transaction_dict = transaction.to_dict() return transaction_dict
def test_transfer_secondsig_transaction(): """Test if a transfer transaction with second signature gets built """ transaction = Transfer( recipientId='AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC', amount=200000000, ) transaction.set_type_group(TRANSACTION_TYPE_GROUP.CORE) transaction.set_nonce(1) transaction.schnorr_sign('this is a top secret passphrase') transaction.second_sign('second top secret passphrase') transaction_dict = transaction.to_dict() assert transaction_dict['nonce'] == 1 assert transaction_dict['signature'] assert transaction_dict['signSignature'] assert transaction_dict['type'] is TRANSACTION_TRANSFER assert transaction_dict['typeGroup'] == 1 assert transaction_dict['typeGroup'] == TRANSACTION_TYPE_GROUP.CORE.value transaction.schnorr_verify( ) # if no exception is raised, it means the transaction is valid transaction.schnorr_verify_second( PublicKey.from_passphrase('second top secret passphrase') ) # if no exception is raised, it means the transaction is valid
def test_transfer_transaction_custom_fee(): """Test if a transfer transaction gets built with a custom fee """ transaction = Transfer(recipientId='AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC', amount=200000000, fee=5) transaction.set_type_group(TRANSACTION_TYPE_GROUP.CORE) transaction.set_nonce(1) transaction.schnorr_sign('this is a top secret passphrase') transaction_dict = transaction.to_dict() assert transaction_dict['nonce'] == 1 assert transaction_dict['signature'] assert transaction_dict['type'] is TRANSACTION_TRANSFER assert transaction_dict['typeGroup'] == 1 assert transaction_dict['typeGroup'] == TRANSACTION_TYPE_GROUP.CORE.value assert transaction_dict['fee'] == 5 transaction.schnorr_verify( ) # if no exception is raised, it means the transaction is valid
def test_transfer_transaction_amount_zero(): with pytest.raises(ValueError): """Test error handling in constructor for non-integer amount """ Transfer(recipientId='AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC', amount=0)