def send_test_funds_to(self, asset, addr_to): send_args = [ asset, addr_to, str(1000), '--from-addr={}'.format(self.wallet_addr) ] print('send_args', send_args) construct_and_send(self, self.Wallet, send_args)
def test_14_owners(self, mock): wallet = self.GetWallet1(recreate=True) args = [ 'gas', self.wallet_1_addr, '2', "--owners=['AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK','APRgMZHZubii29UXF9uFa6sohrsYupNAvx']" ] construct_and_send(None, wallet, args, prompt_password=False) self.assertTrue(mock.called)
def custom_background_code(): wallet = UserWallet.Open(path, to_aes_key(password)) # wallet.Rebuild() # start_wallet_loop(wallet) # print("Opened wallet at %s" % path) print(wallet.ToJson()['percent_synced']) multisig_addr = make_multisig(targetkey, wallet) args = ['GAS', 'AK5q8peiC4QKwuZHWX5Dkqhmar1TAGvZBS', '1'] #testing while wallet._current_height != Blockchain.Default().Height: print("Wallet %s / Blockchain %s" % (str(wallet._current_height), str(Blockchain.Default().Height))) sleep(15) construct_and_send('', wallet, args) print("sent")
def run(self): dbloop = task.LoopingCall(Blockchain.Default().PersistBlocks) dbloop.start(.1) Blockchain.Default().PersistBlocks() while Blockchain.Default().Height < 2: print("Waiting for wallet to sync...") time.sleep(1) print("Creating Wallet...") self.wallet = UserWallet.Create(path=self.wallet_fn, password=self.wallet_pwd) self.wallet.ProcessBlocks() # Extract infos from wallet contract = self.wallet.GetDefaultContract() key = self.wallet.GetKey(contract.PublicKeyHash) address = key.GetAddress() wif = key.Export() print("- Address:", address) print("- WIF key:", wif) self.wallet = None # Claim initial NEO self.claim_initial_neo(address) # Open wallet again self.wallet = UserWallet.Open(self.wallet_fn, self.wallet_pwd) self._walletdb_loop = task.LoopingCall(self.wallet.ProcessBlocks) self._walletdb_loop.start(1) print("\nWait %s min before claiming GAS." % self.min_wait) time.sleep(60 * self.min_wait) print("\nSending NEO to own wallet...") tx = construct_and_send(None, self.wallet, ["neo", address, "100000000"], prompt_password=False) if not tx: print("Something went wrong, no tx.") return # Wait until transaction is on blockchain self.wait_for_tx(tx) print("Claiming the GAS...") claim_tx, relayed = ClaimGas(self.wallet, require_password=False) self.wait_for_tx(claim_tx) # Finally, need to rebuild the wallet self.wallet.Rebuild() print("\nAll done!") print("- WIF key: %s" % wif) print("- Wallet file: %s" % self.wallet_fn) print("- Wallet pwd: %s" % self.wallet_pwd) if self.wif_fn: with open(self.wif_fn, "w") as f: f.write(wif) self.quit()
def test_15_send_0(self): wallet = self.GetWallet1(recreate=True) args = ['neo', "AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK", "0.00"] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertFalse(res)
def test_3_insufficient_funds(self): wallet = self.GetWallet1(recreate=True) args = ['gas', self.watch_addr_str, '101'] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertFalse(res)
def test_2_send_gas(self): wallet = self.GetWallet1(recreate=True) args = ['gas', self.watch_addr_str, '50'] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertTrue(res)
def test_4_bad_assetid(self): wallet = self.GetWallet1(recreate=True) args = ['blah', self.watch_addr_str, '12'] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertFalse(res)
def test_5_negative(self): wallet = self.GetWallet1(recreate=True) args = ['neo', self.watch_addr_str, '-12'] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertFalse(res)
def test_6_weird_amount(self): wallet = self.GetWallet1(recreate=True) args = ['neo', self.watch_addr_str, '12.abc3'] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertFalse(res)
def test_2_send_gas(self): wallet = self.GetWallet1(recreate=True) args = ['gas', self.watch_addr_str, '5'] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertTrue(res)
def test_3_insufficient_funds(self): wallet = self.GetWallet1(recreate=True) args = ['gas', self.watch_addr_str, '72620'] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertFalse(res)
def test_11_bad_attributes(self): wallet = self.GetWallet1(recreate=True) args = ['gas', self.watch_addr_str, '2', '--tx-attr=[{"usa:241"data":his is a remark"}]'] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertTrue(res) self.assertEqual(1, len(res.Attributes))
def run(self): dbloop = task.LoopingCall(Blockchain.Default().PersistBlocks) dbloop.start(.1) Blockchain.Default().PersistBlocks() while Blockchain.Default().Height < 2: print("Waiting for chain to sync...") time.sleep(1) # Claim initial MFF address = "AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y" self.claim_initial_neo(address) # Open wallet again print("Opening wallet %s" % self.wallet_fn) self.wallet = UserWallet.Open(self.wallet_fn, to_aes_key("coz")) self.wallet.ProcessBlocks() self._walletdb_loop = task.LoopingCall(self.wallet.ProcessBlocks) self._walletdb_loop.start(1) # self.wallet.Rebuild() # print("\nOpened wallet. Rebuilding...") # time.sleep(10) print("\nWait %s min before claiming GAS." % self.min_wait) time.sleep(60 * self.min_wait) print("\nSending MFF to own wallet...") tx = construct_and_send(None, self.wallet, ["neo", address, "100000000"], prompt_password=False) if not tx: print("Something went wrong, no tx.") return # Wait until transaction is on blockchain self.wait_for_tx(tx) print("Claiming the GAS...") claim_tx, relayed = ClaimGas(self.wallet, require_password=False) self.wait_for_tx(claim_tx) # Finally, need to rebuild the wallet self.wallet.Rebuild() print("\nAll done!") print("- Wallet file: %s" % self.wallet_fn) print("- Wallet pwd: %s" % self.wallet_pwd) if self.wif_fn: with open(self.wif_fn, "w") as f: f.write("KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr") self.quit()
def test_7_send_token_bad(self): wallet = self.GetWallet1(recreate=True) token_hash = 'f8d448b227991cf07cb96a6f9c0322437f1599b9' ImportToken(wallet, token_hash) args = ['NEP5', self.watch_addr_str, '32'] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertFalse(res)
def test_11_bad_attributes(self): wallet = self.GetWallet1(recreate=True) args = [ 'gas', self.watch_addr_str, '2', '--tx-attr=[{"usa:241"data":his is a remark"}]' ] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertTrue(res) self.assertEqual(1, len(res.Attributes))
def test_10_attributes(self): wallet = self.GetWallet1(recreate=True) args = [ 'gas', self.watch_addr_str, '2', "--tx-attr=[{'usage':241,'data':'This is a remark'},{'usage':242,'data':'This is a remark 2'}]" ] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertTrue(res) self.assertEqual(3, len(res.Attributes))
def withdrawFunds(self, wallet, amount, args=None): if args: amount = int(args[0]) # addr_from = self.neo_fund_sc_addr sh_from = self.neo_fund_sc addr_to = self.wallet_addr addr_to_pub = self.wallet_pub # Need to chang this.. # contract = ImportContractAddr(self.Wallet, [sh_from, addr_to_pub]) self.importContract() addr_from = self.contract_addr send_args = [ 'neo', addr_to, str(amount), '--from-addr={}'.format(addr_from) ] construct_and_send(self, self.Wallet, send_args) withdraw_args = [addr_from, 'neo', addr_to, str(amount)]
def invoke_construct_claim(self, claim_type, fs_id, from_addr, to_addr): # # Finding Pubkey for "to_addr" # pub_key = '' # for addr in self.Wallet.PubKeys(): # if addr['Address'] == to_addr: # pub_key = addr['Public Key'] # # Importing Contract to Pubkey(to_addr) # import_contract_args = [self.SC_hash, pub_key] # from_addr = ImportContractAddr(self.Wallet, import_contract_args) # # from_addr = '' # # print('from_addr', from_addr) # Pre Claim Invoke (Unlock funds to "to_addr") to_addr_data = lookup_addr_str(self.Wallet, to_addr).Data self.invoke_construct(claim_type, [self.project_id, fs_id, to_addr_data]) # Checking amount owed on contract storage (Instant/No Fee) claim_owed_raw = self.invoke_construct('check_claim_owed', [self.project_id, to_addr_data], readonly=True, wait=True) print('claim_owed_raw', claim_owed_raw) claim_owed = claim_owed_raw[0].GetBigInteger() / Fixed8.D print('Current owing (Verified):', claim_owed) if claim_owed > 0: # Calim Verification Tx verification_args = [ 'gas', to_addr, str(claim_owed), '--from-addr=' + str(from_addr) ] print('verification_args', verification_args) construct_and_send(self, self.Wallet, verification_args)
def test_8_send_token_ok(self): wallet = self.GetWallet1(recreate=True) token_hash = '31730cc9a1844891a3bafd1aa929a4142860d8d3' ImportToken(wallet, token_hash) args = [ 'NXT4', self.watch_addr_str, '32', '--from-addr=%s' % self.wallet_1_addr ] res = construct_and_send(None, wallet, args, prompt_password=False) self.assertTrue(res)
def run(self): dbloop = task.LoopingCall(Blockchain.Default().PersistBlocks) dbloop.start(.1) Blockchain.Default().PersistBlocks() while Blockchain.Default().Height < 2: print("Waiting for chain to sync...") time.sleep(1) # Open wallet again print("Opening wallet %s" % self.wallet_fn) self.wallet = UserWallet.Open(self.wallet_fn, to_aes_key("coz")) self.wallet.ProcessBlocks() self._walletdb_loop = task.LoopingCall(self.wallet.ProcessBlocks) self._walletdb_loop.start(1) print("\nWait %s min before claiming GAS." % self.min_wait) time.sleep(60 * self.min_wait) self.wallet.Rebuild() print("\nRebuilding wallet...") time.sleep(20) print("\nSending MFF to own wallet...") address = "AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y" tx = construct_and_send(None, self.wallet, ["neo", address, "100000000"], prompt_password=False) if not tx: print("Something went wrong, no tx.") return # Wait until transaction is on blockchain self.wait_for_tx(tx) print("Claiming the GAS...") claim_tx, relayed = ClaimGas(self.wallet, require_password=False) self.wait_for_tx(claim_tx) # Finally, need to rebuild the wallet # self.wallet.Rebuild() self.quit()
def process_refund_job(self): if len(self.job) != self.operation_args_array_length: self.logger.error( 'ERROR! must have exactly %d operation args, not %d. skipping! %s', self.operation_args_array_length, len(self.job), self.job) self.job = None self.process_job() return # bl: tx can fail if there are no connected peers, so wait for one self.wait_for_peers() self.logger.debug('processing refund: %s', self.job) # in case we have to rebuild the wallet and try the job again, pass in a new list to construct_and_send # since internally the method actually has a side effect of modifying the array to strip out the from address result = construct_and_send(None, self.wallet, list(self.job), False) if not result: self.wallet_needs_recovery = True else: self.job = None self.tx_processing = result.Hash
def do_send(self, arguments): construct_and_send(self, self.Wallet, arguments)
def do_send(self, arguments): return construct_and_send(self, self.Wallet, arguments, False)
def run(self): # settings.set_loglevel(logging.DEBUG) # settings.set_log_smart_contract_events(True) dbloop = task.LoopingCall(Blockchain.Default().PersistBlocks) dbloop.start(.1) self.closeWallet() self.openWallet() print(self.Wallet.ToJson()['percent_synced']) while self.Wallet._current_height < Blockchain.Default().Height: print("Wallet %s / Blockchain %s" % (str(self.Wallet._current_height), str(Blockchain.Default().Height))) sleep(1) f = open("request_neo2002.csv", "w") f.write('targetkey') f.write(',') f.write('neo') f.write(',') f.write('neo sent') f.write(',') f.write('gas') f.write(',') f.write('gas sent') f.write(',') f.write('multisig') f.write(',') f.write('email') f.write('\n') currentkeys = targetkeys while currentkeys != {}: for targetkey in currentkeys: self.closeWallet() self.openWallet() multisig_addr = self.makeMultisig(targetkey) try: gas_amount = currentkeys[targetkey]['gas'] except: gas_amount = 0 pass try: neo_amount = currentkeys[targetkey]['neo'] except: neo_amount = 0 pass if gas_amount > 1000: gas_amount = 1000 if neo_amount > 1000: neo_amount = 1000 argsGAS = ['GAS', multisig_addr, str(gas_amount)] #testing argsNEO = ['NEO', multisig_addr, str(neo_amount)] #testing # argsGAS = ['GAS',multisig_addr,str(1)]#testing # argsNEO = ['NEO',multisig_addr,str(1)]#testing while self.Wallet._current_height < Blockchain.Default( ).Height: print("Wallet %s / Blockchain %s" % (str(self.Wallet._current_height), str(Blockchain.Default().Height))) sleep(5) neo_is_sent = construct_and_send(to_aes_key(password), self.Wallet, argsNEO, prompt_password=False) gas_is_sent = construct_and_send(to_aes_key(password), self.Wallet, argsGAS, prompt_password=False) if neo_is_sent and gas_is_sent: f.write(targetkey) f.write(',') f.write(str(neo_amount)) f.write(',') if neo_is_sent: f.write("yes") else: f.write("no") f.write(',') f.write(str(gas_amount)) f.write(',') if gas_is_sent: f.write("yes") else: f.write("no") f.write(',') f.write(multisig_addr) f.write(',') f.write(targetkeys[targetkey]['email']) f.write('\n') currentkeys = self.removekey(currentkeys, targetkey) else: if neo_is_sent: currentkeys[targetkey] = self.removekey( currentkeys[targetkey], "neo") elif gas_is_sent: currentkeys[targetkey] = self.removekey( currentkeys[targetkey], "gas") print("sent") f.close()