Exemple #1
0
    async def from_buffer(cls, buffer, cursor=0):
        md = dict()
        md['result'] = None # This should be populated elsewhere

        md['sender'] = buffer[cursor:cursor+ADDRESS_LENGTH]
        cursor += ADDRESS_LENGTH
        md['sender'] = address_from_hash(md['sender'])

        md['contractAddress'] = buffer[cursor:cursor+ADDRESS_LENGTH]
        cursor += ADDRESS_LENGTH
        md['contractAddress'] = address_from_hash(md['contractAddress'])
        return cursor, md
Exemple #2
0
def get_address(public_key=None, private_key=None, chain_id=1, prefix="NULS"):
    if public_key is None:
        public_key = get_public_key(private_key=private_key)

    return address_from_hash(
        public_key_to_hash(public_key, chain_id=chain_id), prefix=prefix
    )
Exemple #3
0
    async def from_buffer(cls, buffer, cursor=0):
        md = dict()
        md['result'] = None # This should be populated elsewhere

        md['sender'] = buffer[cursor:cursor+ADDRESS_LENGTH]
        cursor += ADDRESS_LENGTH
        md['sender'] = address_from_hash(md['sender'])

        md['contractAddress'] = buffer[cursor:cursor+ADDRESS_LENGTH]
        cursor += ADDRESS_LENGTH
        md['contractAddress'] = address_from_hash(md['contractAddress'])

        # TODO: change value to 256bit bigint
        md['value'] = struct.unpack("q", buffer[cursor:cursor+8])[0]
        cursor += 8
        md['gasLimit'] = struct.unpack("q", buffer[cursor:cursor+8])[0]
        cursor += 8
        md['price'] = struct.unpack("q", buffer[cursor:cursor+8])[0]
        cursor += 8

        pos, md['methodName'] = read_by_length(buffer, cursor=cursor)
        md['methodName'] = md['methodName'].decode('utf-8')
        cursor += pos
        pos, md['methodDesc'] = read_by_length(buffer, cursor=cursor)
        md['methodDesc'] = md['methodDesc'].decode('utf-8')
        cursor += pos
        argslen = int(buffer[cursor])
        cursor += 1
        args = []
        for i in range(argslen):
            arglen = int(buffer[cursor])
            cursor += 1
            arg = []
            for j in range(arglen):
                pos, argcontent = read_by_length(buffer, cursor=cursor)
                cursor += pos
                try:
                    argcontent = argcontent.decode('utf-8')
                except UnicodeDecodeError:
                    LOGGER.warning("Unicode decode error here, passing raw value.")
                arg.append(argcontent)

            args.append(arg)

        md['args'] = args
        return cursor, md
Exemple #4
0
    def to_dict(self):
        val = {
            'value': self.na,
            'lockTime': self.lockTime
        }
        if self.rawScript is not None:
            val['owner'] = self.rawScript.hex()

        if self.address is not None:
            val['address'] = address_from_hash(self.address)
            val['addressHash'] = self.address

        if self.fromHash is not None:
            val['fromHash'] = self.fromHash.hex()
            val['fromIndex'] = self.fromIndex

        return val
Exemple #5
0
def nuls1to2(address, chain_id, prefix):
    addrhash = b58_decode(address)[2:-1]
    addr_type = addrhash[0]
    addrhash = bytes(struct.pack("h", chain_id)) + \
               addrhash
    return address_from_hash(addrhash, prefix=prefix)
Exemple #6
0
async def get_address(pubkey, chain_id, prefix):
    phash = public_key_to_hash(pubkey, chain_id=chain_id)
    address = address_from_hash(phash, prefix=prefix)
    return address
Exemple #7
0
 def get_address(self):
     return address_from_hash(public_key_to_hash(self.get_public_key(),
                                                 chain_id=self.chain_id),
                              prefix=self.prefix)