Repository: fetchai/tools-pocketbook

Issue:
Pocketbook transfer to show transaction ID
It would be great if doing a transfer using pocketbook resulted in the transaction ID being posted so that it can be fed into the block-explorer, and also sent to people as "verification" of a transaction being sent.


Comments:

Patch:
diff --git a/pocketbook/commands/list.py b/pocketbook/commands/list.py
index 8a8d8c1..7db9d6e 100644
--- a/pocketbook/commands/list.py
+++ b/pocketbook/commands/list.py
@@ -1,5 +1,5 @@
 from fnmatch import fnmatch
-
+import warnings
 
 def _should_display(item, patterns):
     return any([fnmatch(item, p) for p in patterns])
@@ -11,6 +11,9 @@ def run_list(args):
     from pocketbook.table import Table
     from pocketbook.utils import create_api, get_balance, get_stake, token_amount
 
+    # the latest version of SDK will generate warning because we are using the staking API
+    warnings.simplefilter('ignore')
+
     address_book = AddressBook()
     key_store = KeyStore()
     keys = key_store.list_keys()
diff --git a/pocketbook/commands/transfer.py b/pocketbook/commands/transfer.py
index d88e64c..853afd5 100644
--- a/pocketbook/commands/transfer.py
+++ b/pocketbook/commands/transfer.py
@@ -85,10 +85,25 @@ def run_transfer(args):
     tx = TokenTxFactory.transfer(Address(from_address), destination, amount, 0, signers)
     tx.charge_rate = charge_rate
     tx.charge_limit = required_ops
+    api.set_validity_period(tx)
     for entity in signers:
         tx.sign(entity)
 
+    tx_digest = api.submit_signed_tx(tx)
+    print('TX: 0x{} submitted'.format(tx_digest))
+
     # submit the transaction
-    print('Submitting TX...')
-    api.sync(api.submit_signed_tx(tx))
-    print('Submitting TX...complete')
+    print('Waiting for transaction to be confirmed...')
+    api.sync(tx_digest)
+    print('Waiting for transaction to be confirmed...complete')
+
+    # determine if there is a block explorer link to be printed
+    explorer_link = None
+    if args.network == 'mainnet':
+        explorer_link = 'https://explore.fetch.ai/transactions/0x{}'.format(tx_digest)
+    elif args.network == 'testnet':
+        explorer_link = 'https://explore-testnet.fetch.ai/transactions/0x{}'.format(tx_digest)
+
+    if explorer_link is not None:
+        print()
+        print('See {} for more details'.format(explorer_link))
\ No newline at end of file
diff --git a/setup.py b/setup.py
index ab98625..b457b8d 100644
--- a/setup.py
+++ b/setup.py
@@ -32,7 +32,7 @@ setup(
         'Programming Language :: Python :: 3.7',
     ],
     install_requires=[
-        'fetchai-ledger-api==1.0.0',
+        'fetchai-ledger-api==1.0.1',
         'toml',
         'colored',
     ],


Test patch:
diff --git a/tests/commands/test_transfer.py b/tests/commands/test_transfer.py
index 17dfc0f..88d8665 100644
--- a/tests/commands/test_transfer.py
+++ b/tests/commands/test_transfer.py
@@ -65,6 +65,7 @@ class TransferCommandUnitTests(unittest.TestCase):
                                                        [person1.entity])
         self.assertEqual(tx.charge_rate, 1)
         self.assertEqual(tx.charge_limit, 1)
+        api.set_validity_period.assert_called_once_with(tx)
         tx.sign.assert_called_with(person1.entity)
 
         # submission of the transaction
@@ -118,6 +119,7 @@ class TransferCommandUnitTests(unittest.TestCase):
                                                        [person1.entity])
         self.assertEqual(tx.charge_rate, 2)
         self.assertEqual(tx.charge_limit, 1)
+        api.set_validity_period.assert_called_once_with(tx)
         tx.sign.assert_called_with(person1.entity)
 
         # submission of the transaction
@@ -170,6 +172,7 @@ class TransferCommandUnitTests(unittest.TestCase):
                                                        [person1.entity])
         self.assertEqual(tx.charge_rate, 1)
         self.assertEqual(tx.charge_limit, 1)
+        api.set_validity_period.assert_called_once_with(tx)
         tx.sign.assert_called_with(person1.entity)
 
         # submission of the transaction
@@ -226,6 +229,7 @@ class TransferCommandUnitTests(unittest.TestCase):
                                                        [person1.entity])
         self.assertEqual(tx.charge_rate, 1)
         self.assertEqual(tx.charge_limit, 1)
+        api.set_validity_period.assert_called_once_with(tx)
         tx.sign.assert_called_with(person1.entity)
 
         # submission of the transaction