OSDN Git Service

fix receiver bug
[bytom/pybtm.git] / README.md
index 0a91863..2b9ee84 100644 (file)
--- a/README.md
+++ b/README.md
@@ -16,6 +16,11 @@ pybtm
   - [2.11 Verify signature](#211-verify-signature)
   - [2.12 Create new key](#212-create-new-key)
   - [2.13 Create HD path](#213-create-hd-path)
+  - [2.14 Create control program](#214-create-control-program)
+  - [2.15 Create address](#215-create-address)
+  - [2.16 Create new address](#216-create-new-address)
+  - [2.17 Submit raw transaction](#217-submit-raw-transaction)
+  - [2.18 Decode raw transaction](#218-decode-raw-transaction)
 
 Python3 implementation of the Bytom protocol.
 
@@ -25,6 +30,10 @@ Python3 implementation of the Bytom protocol.
 $ pip install pybtm
 ```
 
+Requires:
+
+- Python>=3.7
+
 ## 2 Usage
 
 ### 2.1 Create entropy
@@ -323,3 +332,129 @@ Return:
 >>> receiver.get_path_from_index(account_index_int, address_index_int, change_bool)
 {'path': ['2c000000', '99000000', '01000000', '01000000', '01000000'], 'path_str': 'm/44/153/1/1/1'}
 ```
+
+### 2.14 Create control program
+
+get_control_program create control program.
+
+Parameter:
+
+- account_index_int: account index, e.g. 1, 2, 3...
+- address_index_int: address index, e.g. 1, 2, 3...
+- change_bool: If receiver is change, change_bool is True, otherwise the change_bool is False.
+- xpub_hexstr: 512 bits expanded public key, type is hex string.
+
+Return:
+
+- control_program_hexstr: type is hex string.
+
+```python
+>>> from pybtm import receiver
+>>> account_index_int = 1
+>>> address_index_int = 1
+>>> change_bool = False
+>>> xpub_hexstr = '3c6664244d2d57168d173c4691dbf8741a67d972b2d3e1b0067eb825e2005d20c5eebd1c26ccad4de5142d7c339bf62cc1fb79a8b3e42a708cd521368dbc9286'
+>>> receiver.get_control_program(account_index_int, address_index_int, change_bool, xpub_hexstr)
+'0014052620b86a6d5e07311d5019dffa3864ccc8a6bd'
+```
+
+### 2.15 Create address
+
+get_address create address from control program.
+
+Parameter:
+
+- control_program_hexstr: control program.
+- network_str: 3 types of network is available: mainnet, testnet and solonet.
+
+Return:
+
+- address: bytom address.
+
+```python
+>>> from pybtm import receiver
+>>> control_program_hexstr = '001431f2b90b469e89361225aae370f73e5473b9852b'
+>>> network_str = 'mainnet'
+>>> receiver.get_address(control_program_hexstr, network_str)
+'bm1qx8etjz6xn6ynvy394t3hpae723emnpft3nrwej'
+```
+
+### 2.16 Create new address
+
+get_new_address create new address.
+
+Parameter:
+
+- xpub_hexstr: 512 bits expanded public key, type is hex string.
+- account_index_int: account index, e.g. 1, 2, 3...
+- address_index_int: address index, e.g. 1, 2, 3...
+- change_bool: If receiver is change, change_bool is True, otherwise the change_bool is False.
+- network_str: 3 types of network is available: mainnet, testnet and solonet.
+
+Return:
+
+- path: BIP44 HD path.
+- control program: control program.
+- address: bytom address.
+- address_base64: bytom address image base64.
+
+```python
+>>> from pybtm import receiver
+>>> xpub_hexstr = '8fde12d7c9d6b6cbfbf344edd42f2ed86ae6270b36bab714af5fd5bb3b54adcec4265f1de85ece50f17534e42016ee9404a11fec94ddfadd4a064d27ef3f3f4c'
+>>> account_index_int = 1
+>>> address_index_int = 1
+>>> change_bool = False
+>>> network_str = 'solonet'
+>>> receiver.get_new_address(xpub_hexstr, account_index_int, address_index_int, change_bool, network_str)
+{'path': 'm/44/153/1/0/1', 'control_program': '00147640f3c34fe4b2b298e54e54a4692a47ce47aa5e', 'address': 'sm1qweq08s60ujet9x89fe22g6f2gl8y02j7lgr5v5', 'address_base64': '/9j/4AAQSkZJRgAB...'}
+```
+
+### 2.17 Submit raw transaction
+
+submit_transaction submit transaction.
+
+Parameter:
+
+- raw_transaction_hexstr: raw transaction.
+- submit_url: you can send raw transaction through submit_url.
+
+Return:
+
+- result: If submit transaction successfully, result is 1.
+
+```python
+>>> from pybtm import transaction
+>>> raw_transaction_hexstr = '070100010160015e5dfc352f9247985e92b2688a9a0a0e3e45a52f633c7d2c35cf6485fc1f03a89cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8094ebdc030101160014052620b86a6d5e07311d5019dffa3864ccc8a6bd630240988348a301c86563eb16105cc0c7e12e8cd1fbc7e9031933dac05a32d2a696bc77b83f25a99a4a9458d976c5327b8004918545a3fde567f28d805f741db54e0b20e87ca3acdebdcad9a1d0f2caecf8ce0dbfc73d060807a210c6f225488347961402013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80b6f7f302011600147950bb5fcfb1c3fe14198c14ebd4ad85bb69bbc500013cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8084af5f011600141d8e1c2d71843f41e2131d7fd6df8b47e2cf56b900'
+>>> submit_url = 'https://blockmeta.com/api/wisdom/broadcast-transaction'
+>>> transaction.submit_transaction(raw_transaction_hexstr, submit_url)
+'1'
+```
+
+```python
+>>> from pybtm import transaction
+>>> raw_transaction_hexstr = '07010001015f015d2f4a8f10afbc0448779fadd916a3f1b8518ffe0b7d20fdf470d8e9b4993ef2b4ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0d8883200011600144a594e3e4cbbd87629476e7ee24c1637df66c0b76302406fd39079681118840fd6fd66cdff769f2d05d8520312e9dd559dc23c36a3cb3921e47cba233d5d2267eb0f128a908d1bab877e172e880d3f36dc6a5e5826540c202854e5c181f5a862edd190e413d75937549758ef4902e1475aac52623f0a239302013cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc09dd81001160014f63f68597df5c88a92e04229e0fd08a3584ade3b00013cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80e1eb1701160014664f28ec6ab8826a028658dc0d0d1f94c6e20fa300'
+>>> submit_url = 'https://blockmeta.com/api/v2/broadcast-transaction'
+>>> transaction.submit_transaction(raw_transaction_hexstr, submit_url)
+'1'
+```
+
+### 2.18 Decode raw transaction
+
+decode_raw_tx decode raw transaction.
+
+Parameter:
+
+- raw_transaction_hexstr: raw transaction, type is hex string.
+- network_str: 3 types of network is available: mainnet, testnet and solonet.
+
+Return:
+
+- tx: tx dict.
+
+```python
+>>> from pybtm import transaction
+>>> raw_transaction_hexstr = '070100010161015f28b7b53d8dc90006bf97e0a4eaae2a72ec3d869873188698b694beaf20789f21ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d5990100011600149335b1cbd4a77b78e33315a0ed10a95b12e7ca48630240897e2d9d24a3b5faaed0579dee7597b401491595675f897504f8945b29d836235bd2fca72a3ad0cae814628973ebcd142d9d6cc92d0b2571b69e5370a98a340c208cb7fb3086f58db9a31401b99e8c658be66134fb9034de1d5c462679270b090702013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80f9f8bc98010116001406ce4b689ba026ffd3a7ca65d1d059546d4b78a000013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80c6868f01011600147929ef91997c827bebf60fa608f876ea27523c4700'
+>>> network_str = 'solonet'
+>>> transaction.decode_raw_tx(raw_transaction_hexstr, network_str)
+{'fee': 20000000, 'inputs': [{'address': 'sm1qjv6mrj755aah3cenzksw6y9ftvfw0jjgk0l2mw', 'amount': 41250000000, 'asset_definition': {}, 'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'control_program': '00149335b1cbd4a77b78e33315a0ed10a95b12e7ca48', 'input_id': '6e3f378ed844b143a335e306f4ba26746157589c87e8fc8cba6463c566c56768', 'spent_output_id': 'f229ec6f403d586dc87aa2546bbe64c5f7b5f46eb13c6ee4823d03bc88a7cf17', 'type': 'spend', 'witness_arguments': ['897e2d9d24a3b5faaed0579dee7597b401491595675f897504f8945b29d836235bd2fca72a3ad0cae814628973ebcd142d9d6cc92d0b2571b69e5370a98a340c', '8cb7fb3086f58db9a31401b99e8c658be66134fb9034de1d5c462679270b0907']}], 'outputs': [{'address': 'sm1qqm8yk6ym5qn0l5a8efjar5ze23k5k79qnvtslj', 'amount': 40930000000, 'asset_definition': {}, 'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'control_program': '001406ce4b689ba026ffd3a7ca65d1d059546d4b78a0', 'id': '74c73266730d3c6ea32e8667ef9b867068736b84be240fe9fef205fa68bb7b95', 'position': 0, 'type': 'control'}, {'address': 'sm1q0y57lyve0jp8h6lkp7nq37rkagn4y0z8hvh6kq', 'amount': 300000000, 'asset_definition': {}, 'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'control_program': '00147929ef91997c827bebf60fa608f876ea27523c47', 'id': 'f115a833d0c302a5006032858a7ed3987f0feb2daf2a9f849384950e4766af51', 'position': 1, 'type': 'control'}], 'size': 333, 'time_range': 0, 'tx_id': '814a73dd57bae67c604f9cbc696cbc42035577423408cb9267136ed971e2bf63', 'version': 1}
+```
\ No newline at end of file