OSDN Git Service

add path_list test data
authorChengcheng Zhang <943420582@qq.com>
Mon, 7 Jan 2019 07:13:37 +0000 (15:13 +0800)
committerChengcheng Zhang <943420582@qq.com>
Mon, 7 Jan 2019 07:13:37 +0000 (15:13 +0800)
app/api/__init__.py
app/api/resources.py
app/model/receiver.py
app/model/segwit_addr.py

index 895d0b1..9d7e0c8 100644 (file)
@@ -17,6 +17,7 @@ from app.api.resources import Xprv_To_Child_Xprv
 from app.api.resources import Xpub_To_Child_Xpub
 from app.api.resources import Create_P2WPKH_Program
 from app.api.resources import Create_Address
+from app.api.resources import Get_Path_From_Index
 
 blueprint = Blueprint('api', __name__, url_prefix='/api/v1')
 api = Api(blueprint)
@@ -36,4 +37,5 @@ api.add_resource(Xprv_To_Xpub, '/xprv_to_xpub')
 api.add_resource(Xprv_To_Child_Xprv, '/xprv_to_child_xprv')
 api.add_resource(Xpub_To_Child_Xpub, '/xpub_to_child_xpub')
 api.add_resource(Create_P2WPKH_Program, '/create_P2WPKH_program')
-api.add_resource(Create_Address, '/create_address')
\ No newline at end of file
+api.add_resource(Create_Address, '/create_address')
+api.add_resource(Get_Path_From_Index, '/get_path_from_index')
\ No newline at end of file
index 90ca20b..8eff581 100644 (file)
@@ -18,6 +18,7 @@ from app.model.key import xprv_to_child_xprv
 from app.model.key import xpub_to_child_xpub
 from app.model.receiver import create_P2WPKH_program
 from app.model.receiver import create_address
+from app.model.receiver import get_path_from_index
 
 parser = reqparse.RequestParser()
 parser.add_argument('private_key_str', type=str)
@@ -151,6 +152,17 @@ class Xpub_To_Child_Xpub(Resource):
         child_xpub = xpub_to_child_xpub(xpub, path)
         return child_xpub
 
+class Get_Path_From_Index(Resource):
+
+    def post(self):
+        args = parser.parse_args()
+        account_index = args.get('account_index_int')
+        address_index = args.get('address_index_int')
+        change = args.get('change_bool')
+        path_list = get_path_from_index(account_index, address_index, change)
+        return path_list
+
+
 class Create_P2WPKH_Program(Resource):
 
     def post(self):
index 598f06d..e51897a 100644 (file)
@@ -3,13 +3,28 @@ from app.model.key import *
 from app.model import segwit_addr
 
 # get_path_from_index create xpub path from account key index and current address index
+# path: purpose(0x2c=44)/coin_type(btm:0x99)/account_index/change(1 or 0)/address_index
+# You can find more details from: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
+# You can get more test data from: https://gist.github.com/zcc0721/616eaf337673635fa5c9dd5dbb8dd114
 # Please attention:
 #   account_index_int >= 1
 #   address_index_int >= 1
+#   change_bool: true or false
 # test data 1:
-#   account_index_int: 
-#   address_index_int: 
-#   path_list: 
+#   account_index_int: 1
+#   address_index_int: 1
+#   change_bool: true
+#   path_list: 2c000000 99000000 01000000 01000000 01000000
+# test data 2:
+#   account_index_int: 1
+#   address_index_int: 1
+#   change_bool: false
+#   path_list: 2c000000 99000000 01000000 00000000 01000000
+# test data 3:
+#   account_index_int: 3
+#   address_index_int: 1
+#   change_bool: false
+#   path_list: 2c000000 99000000 03000000 00000000 01000000
 def get_path_from_index(account_index_int, address_index_int, change_bool):
     path_list = ['2c000000', '99000000']
     account_index_str = (account_index_int).to_bytes(4, byteorder='little').hex()
@@ -38,22 +53,14 @@ def create_P2WPKH_program(account_index_int, address_index_int, change_bool, xpu
 
     return control_program_str
 
+
 def create_address(control_program_str, network_str):
-    # path_list = get_path_from_index(account_index_int, address_index_int, change_bool)
-    # child_xpub_str = xpub_to_child_xpub(xpub_str, path_list)
-    # child_public_key_str = xpub_to_public_key(child_xpub_str)
-    # child_public_key_byte = bytes.fromhex(child_public_key_str)
-    
-    # ripemd160 = hashlib.new('ripemd160')
-    # ripemd160.update(child_public_key_byte)
     public_key_hash_str = control_program_str[4:]
-    # control_program_str = '0014' + public_key_hash_str
-
     if network_str == 'mainnet':
         hrp = 'bm'
     elif network_str == 'testnet':
         hrp = 'tm'
-    elif network_str == 'solonet':
+    else:
         hrp = 'sm'
     address_str = segwit_addr.encode(hrp, 0, bytes.fromhex(public_key_hash_str))
 
index e0df3b6..01edb6b 100644 (file)
@@ -17,6 +17,8 @@
 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 # THE SOFTWARE.
+#
+# Please Ref: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki
 
 """Reference implementation for Bech32 and segwit addresses."""