55from itertools import chain
66
77from pysodium import crypto_sign_BYTES as SIGNATURE_SZ
8- from pysodium import crypto_sign_detached
8+ from pysodium import crypto_sign_detached , crypto_hash_sha256
99
1010from .datatypes import EncodingStruct , ExonumBase , TxHeader
1111from .error import IllegalServiceId , NotEncodingStruct
@@ -24,7 +24,7 @@ def tx(self, secret_key, hex=False):
2424 header_fmt ,
2525 buf ,
2626 0 ,
27- kwargs [ "network_id" ],
27+ 0 , # network_id field doesn't use anymore but place is reserved with value 0
2828 kwargs ["protocol_version" ],
2929 kwargs ["message_id" ],
3030 kwargs ["service_id" ],
@@ -43,13 +43,12 @@ def tx(self, secret_key, hex=False):
4343
4444
4545class transactions (object ):
46- def __init__ (self , service_id = - 1 , protocol_version = 0 , network_id = 0 ):
46+ def __init__ (self , service_id = - 1 , protocol_version = 0 ):
4747 if service_id < 0 :
4848 raise IllegalServiceId ()
4949
5050 self .service_id = service_id
5151 self .protocol_version = protocol_version
52- self .network_id = network_id
5352 self .tx = []
5453
5554 @staticmethod
@@ -69,7 +68,11 @@ def __call__(self, cls):
6968 class Tx (tx_cls ):
7069 def __init__ (tx_self , * args , ** kwargs ):
7170 if "message_id" not in kwargs :
72- kwargs ["network_id" ] = self .network_id
71+ kwargs [
72+ "network_id"
73+ ] = (
74+ 0
75+ ) # network_id field doesn't use anymore but place is reserved with value 0
7376 kwargs ["protocol_version" ] = self .protocol_version
7477 kwargs ["message_id" ] = message_id
7578 kwargs ["service_id" ] = self .service_id
@@ -96,7 +99,15 @@ def tx(self, secret_key, hex=False):
9699 k : v for k , v in plain .items () if k not in meta_fields
97100 }
98101 del message ["payload_sz" ]
102+ del message [
103+ "network_id"
104+ ] # network_id field doesn't use anymore in JSON
99105 return message
100106
107+ def hash (self , secret_key ):
108+ tx_bytes = self .tx (secret_key , hex = True )
109+ tx_hash = crypto_hash_sha256 (tx_bytes )
110+ return codecs .encode (tx_hash , "hex" ).decode ("utf-8" )
111+
101112 self .tx .append (cls .__name__ )
102113 return Tx
0 commit comments