OSDN Git Service

combine with btmsender
authorsuccessli <successli@outlook.com>
Mon, 25 Jun 2018 09:38:27 +0000 (17:38 +0800)
committersuccessli <successli@outlook.com>
Mon, 25 Jun 2018 09:38:27 +0000 (17:38 +0800)
btmspanner.py
utxomerger/README.md
utxomerger/Transaction.py
utxomerger/account_test.py [deleted file]
utxomerger/merge_utxo.py
utxomerger/transaction_test.py [deleted file]
utxomerger/unspent_outputs_test.py [deleted file]

index e546136..64a2f8f 100755 (executable)
@@ -2,16 +2,17 @@
 
 import sys
 from btmsender import btmsender
+from utxomerger import merge_utxo
 
 if __name__ == "__main__":
     if sys.argv[1] == 'btmsender':
         sys.argv.pop(1)
         sys.exit(btmsender.sender())
-    elif sys.argv[1] == 'utxocombiner':
+    elif sys.argv[1] == 'utxomerger':
         sys.argv.pop(1)
-        # TODO
+        sys.exit(merge_utxo.main())
     else:
         print("Input error:\n"
               "btmsender usage: btmspanner.py btmsender [-h] -i I -a A -p P [-c C]"
-              "utxocombiner usage: btmspanner.py utxocombiner")
+              "utxomerger usage: btmspanner.py utxomerger [-h] [-o URL] [-a ACCOUNT_ALIAS] [-p PASSWORD] [-x MAX_AMOUNT] [-s MIN_AMOUNT] [-l] [-m MERGE_LIST] [-y]")
         sys.exit(1)
index deada7d..80455c0 100644 (file)
@@ -1,4 +1,4 @@
-# UTXO combiner
+# UTXO merger
 
 Requirements: Python 3.x, with requests package
 
@@ -12,6 +12,7 @@ Usage:
     ./bytomd init --chain_id mainnet
    ```
    ```
+    cd utxomerger
     python merge_utxo.py [options]
    ```
    If you don't know how to run bytomd please check this [wiki](https://github.com/Bytom/bytom/wiki/Build-and-Install)
@@ -42,18 +43,18 @@ optional arguments:
 
 Example:
    ```shell
-python merge_utxo.py -o http://127.0.0.1:9888 -a sheng -p 123456 -x 41250000000 -s 0 -l
+python btmspanner.py utxomerger -o http://127.0.0.1:9888 -a sheng -p 123456 -x 41250000000 -s 0 -l   
    ```
 
    or
 
    ```shell
-python merge_utxo.py -o http://127.0.0.1:9888 -a sheng -p 123456 -x 41250000000 -s 0 -m 10
+python btmspanner.py utxomerger -o http://127.0.0.1:9888 -a sheng -p 123456 -x 41250000000 -s 0 -m 10
    ```
 
 Result:
 ```shell
-$ python merge_utxo.py -o http://127.0.0.1:9888 -a sheng -p 123456 -x 41250000000 -s 0 -m 10
+python btmspanner.py utxomerger -o http://127.0.0.1:9888 -a sheng -p 123456 -x 41250000000 -s 0 -l   
    0.  412.50000000 BTM f9c0d3831061edcf045e13e1a6408cb1794817290fceed1ef41fcbd809ef24d4 (mature)
    1.  412.50000000 BTM f98e8faf54ee9731578e973ab44dbdd2001fd254d34f5e8982de1cee0fc95126 (mature)
    2.  325.00000000 BTM f9864118a26f852149ac84d7d5b5da2bb97fb390a929a98faf3f3187c6ac6c35 (mature)
index 0e20095..cf4e29e 100644 (file)
@@ -1,6 +1,6 @@
 import json
 
-from Account import Account
+from .Account import Account
 
 
 class Transaction(object):
diff --git a/utxomerger/account_test.py b/utxomerger/account_test.py
deleted file mode 100644 (file)
index b304889..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-import unittest
-
-from Account import Account
-from connection import Connection
-from keys import Keys
-
-
-class TestAccountMethods(unittest.TestCase):
-
-    def test_list(self):
-        con = Connection("http://127.0.0.1:9888")
-        account_list = Account.list(con)
-        for account in account_list:
-            print(account.id, account.alias, account.xpubs, account.key_index, account.quorum)
-        self.assertIsNotNone(account_list)
-
-    def test_find_by_alias(self):
-        con = Connection("http://127.0.0.1:9888")
-        account = Account.find_by_alias(con, "receiver-account")
-        print(account.id, account.alias, account.xpubs, account.key_index, account.quorum)
-
-    def test_create(self):
-        con = Connection("http://127.0.0.1:9888")
-        xpub = Keys.find_by_alias(con, "test").xpub
-        account = Account.create(con, [xpub], "shengsheng", 1)
-        print(account.id, account.alias, account.xpubs, account.key_index, account.quorum)
-
-    def test_delete(self):
-        con = Connection("http://127.0.0.1:9888")
-        status = Account.delete(con, "shengsheng")
-        self.assertIs("true", status)
-
-    def test_create_address(self):
-        con = Connection("http://127.0.0.1:9888")
-        account = Account.find_by_alias(con, "zhangsan")
-
-        response = Account.create_address(con, "zhangsan", account.id)
-        print(response)
-        print(response['address'])
-
-    if __name__ == '__main__':
-        unittest.main()
index c73969e..30f2e9f 100644 (file)
@@ -1,13 +1,13 @@
 import argparse
 import getpass
-import json
 import os
 import time
 
-from Account import Account
-from Transaction import Action, Transaction
-from UnspentOutputs import UnspentOutputs
-from connection import Connection
+
+from .Account import Account
+from .Transaction import Action, Transaction
+from .UnspentOutputs import UnspentOutputs
+from .connection import Connection
 
 parser = argparse.ArgumentParser(description='Bytom merge utxo tool')
 parser.add_argument('-o', '--url', default='http://127.0.0.1:9888', dest='url', help='API url to connect')
@@ -126,7 +126,7 @@ def main():
     if not to_address:
         to_address = input('Transfer address: ')
 
-    print(send_tx(Connection(options.url), utxo_mergelist, to_address, options.password))
+    print('tx_id:', send_tx(Connection(options.url), utxo_mergelist, to_address, options.password))
 
 
 if __name__ == '__main__':
diff --git a/utxomerger/transaction_test.py b/utxomerger/transaction_test.py
deleted file mode 100644 (file)
index caa7b72..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-import unittest
-
-from Transaction import Transaction, Action
-from connection import Connection
-
-
-class TestTransactionMethods(unittest.TestCase):
-
-    def test_list_transactions(self):
-        con = Connection("http://127.0.0.1:9888")
-        transactions = Transaction.list_transactions(con)
-        for tx in transactions:
-            print(tx)
-
-    def test_list_by_account_id(self):
-        con = Connection("http://127.0.0.1:9888")
-        account_id = "0E6KP8C100A02"
-        transactions = Transaction.list_by_account_id(con, account_id)
-        for tx in transactions:
-            print(tx)
-
-    def test_list_by_account_alias(self):
-        con = Connection("http://127.0.0.1:9888")
-        account_alias = "receiver-account"
-        transactions = Transaction.list_by_account_alias(con, account_alias)
-        for tx in transactions:
-            print(tx)
-
-    def test_get_transaction(self):
-        con = Connection("http://116.62.130.184:9888")
-        tx_id = "eb535916e05ecee1a193ce489e5151c873f459639fcabffdc2df69f7f76fc550"
-        tx, ret = Transaction.get_transaction(con, tx_id)
-        print(tx)
-        print(ret)
-
-    def test_issue_transaction(self):
-        # build transaction
-        con = Connection("http://127.0.0.1:9888")
-        asset_id = 'd2d938352d324e68c21b3c8b3a7f8587f237d100cd5618cc0ba3ba35bbb7185d'
-        account_id = '0E6K7AFF00A02'
-        btm_id = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
-        address = 'sm1qz2j8k5anh0d0nu63pcwccxwkn7qu4y2zjwaj5h'
-        actions = [
-            Action.issue(10000, asset_id),
-            Action.gas(20000000, account_id, btm_id),
-            Action.control_address(10000, asset_id, address)
-        ]
-        print(actions)
-        issuance = Transaction.build_transaction(con, actions)
-        print("issuance:", issuance)
-        # sign transaction
-        signed_raw_transaction = Transaction.sign_transaction(con, '123456', issuance)
-        print("signed_raw_transaction:", signed_raw_transaction)
-        # submit transaction
-        tx_id = Transaction.submit_transaction(con, signed_raw_transaction)
-        print("tx_id:", tx_id)
-
-    def test_spend_transaction(self):
-        # build transaction
-        con = Connection("http://127.0.0.1:9888")
-        asset_id = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
-        account_id = '0F87NG1800A02'
-        btm_id = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
-        address = 'sm1qvyus3s5d7jv782syuqe3qrh65fx23lgpzf33em'
-        actions = [
-            Action.spend_account(125000000000, account_id, asset_id),
-            Action.gas(40000000, account_id, btm_id),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-            Action.control_address(5000000000, asset_id, address),
-        ]
-        print(actions)
-        issuance = Transaction.build_transaction(con, actions)
-        print("issuance:", issuance)
-        # sign transaction
-        signed_raw_transaction = Transaction.sign_transaction(con, '123456', issuance)
-        print("signed_raw_transaction:", signed_raw_transaction)
-        # submit transaction
-        tx_id = Transaction.submit_transaction(con, signed_raw_transaction)
-        print("tx_id:", tx_id)
-
-    if __name__ == '__main__':
-        unittest.main()
diff --git a/utxomerger/unspent_outputs_test.py b/utxomerger/unspent_outputs_test.py
deleted file mode 100644 (file)
index 79bba6b..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-import unittest
-
-from Transaction import Transaction
-from connection import Connection
-from UnspentOutputs import UnspentOutputs
-
-
-class TestUTXOMethods(unittest.TestCase):
-
-    def test_get_block_height(self):
-        con = Connection("http://127.0.0.1:9888")
-        block_height, ret = UnspentOutputs.get_block_height(connection=con)
-        if ret == 1:
-            print(block_height)
-
-    def test_list_UTXO(self):
-        con = Connection("http://127.0.0.1:9888")
-        utxos, ret = UnspentOutputs.list_UTXO(con)
-        if ret == 1:
-            for utxo in utxos:
-                print(utxo)
-
-    if __name__ == '__main__':
-        unittest.main()