示例#1
0
 def validate_proof(proof: List[dict],
                    hex_target_hash: str,
                    hex_merkle_root: str,
                    is_big_endian: bool = False):
     if is_big_endian:
         hex_merkle_root = NeoData.to_reserve_hex_str(hex_merkle_root)
         hex_target_hash = NeoData.to_reserve_hex_str(hex_target_hash)
     if len(proof) == 0:
         return hex_target_hash == hex_merkle_root
     else:
         hex_proof_hash = hex_target_hash
         for node in proof:
             if is_big_endian:
                 sibling = NeoData.to_reserve_hex_str(node['TargetHash'])
             else:
                 sibling = node['TargetHash']
             try:
                 direction = node['Direction'].lower()
             except KeyError:
                 raise SDKException(ErrorCode.other_error('Invalid proof'))
             if direction == 'left':
                 value = bytes.fromhex('01' + sibling + hex_proof_hash)
                 hex_proof_hash = Digest.sha256(value, is_hex=True)
             elif direction == 'right':
                 value = bytes.fromhex('01' + hex_proof_hash + sibling)
                 hex_proof_hash = Digest.sha256(value, is_hex=True)
             else:
                 raise SDKException(ErrorCode.other_error('Invalid proof.'))
         return hex_proof_hash == hex_merkle_root
示例#2
0
def echo_cli_exception(e: Union[PunicaException, SDKException]):
    msg = e.args[1].replace('Other Error, ', '')
    if 'transactor' in msg:
        if isinstance(msg, str):
            words = msg.split(' ')
            words[0] = 'Payer'
            words[1] = NeoData.to_b58_address(
                NeoData.to_reserve_hex_str(words[1]))
            msg = ' '.join(words)
    echo(red(f'\n{msg}\n', bold=True))