static Deserialize(b, isTest = false) {
        const buf = new util_1.default.Reader(b);
        // Parse OP_RETURN op code
        const opCode = buf.uint8();
        if (opCode !== OP_RETURN) {
            throw new Error(sprintf_js_1.sprintf('Not an op return output : %02x', opCode));
        }
        // Parse protocol ID
        const protocolId = isTest ? OpReturnMessage.TestProtocolID : OpReturnMessage.ProtocolID;
        let size = ParsePushDataScript(buf);
        if (size !== protocolId.length) {
            throw new Error(sprintf_js_1.sprintf('Push not correct size for protocol ID : %d != %d', size, protocolId.length));
        }
        const readProtocolId = buf.read(size).toString('ascii');
        if (readProtocolId !== protocolId) {
            throw new Error('Invalid protocol ID:' + readProtocolId);
        }
        // Parse push op code for payload length + 3 for version and message type code
        size = ParsePushDataScript(buf);
        // if uint64(buf.Len()) < payloadSize {
        // 	return nil, sprintf('Payload push op code is too large for message : %d', payloadSize)
        // }
        // Parse version
        const version = buf.uint8();
        if (version !== OpReturnMessage.Version) {
            throw new Error(sprintf_js_1.sprintf('Unsupported version : %02x', version));
        }
        // Parse message type code
        const code = buf.read(2).toString('ascii');
        const msg = actions_1.TypeMapping(code);
        if (!msg) {
            throw new Error(sprintf_js_1.sprintf('Unknown code : %s', code));
        }
        msg.write(buf.read(size - 3));
        return msg;
    }
// Deserialize returns a message, as an OpReturnMessage, from the OP_RETURN script.
Deserialize returns a message, as an OpReturnMessage, from the OP_RETURN script.
Deserialize returns a message as an OpReturnMessage from the OP_RETURN script .
static Deserialize(b, isTest = false) {
        const buf = new util_1.default.Reader(b);
        const opCode = buf.uint8();
        if (opCode !== OP_RETURN) {
            throw new Error(sprintf_js_1.sprintf('Not an op return output : %02x', opCode));
        }
        const protocolId = isTest ? OpReturnMessage.TestProtocolID : OpReturnMessage.ProtocolID;
        let size = ParsePushDataScript(buf);
        if (size !== protocolId.length) {
            throw new Error(sprintf_js_1.sprintf('Push not correct size for protocol ID : %d != %d', size, protocolId.length));
        }
        const readProtocolId = buf.read(size).toString('ascii');
        if (readProtocolId !== protocolId) {
            throw new Error('Invalid protocol ID:' + readProtocolId);
        }
        size = ParsePushDataScript(buf);
        const version = buf.uint8();
        if (version !== OpReturnMessage.Version) {
            throw new Error(sprintf_js_1.sprintf('Unsupported version : %02x', version));
        }
        const code = buf.read(2).toString('ascii');
        const msg = actions_1.TypeMapping(code);
        if (!msg) {
            throw new Error(sprintf_js_1.sprintf('Unknown code : %s', code));
        }
        msg.write(buf.read(size - 3));
        return msg;
    }
static Deserialize ( b , isTest = false ) { const buf = new util_1 . default . Reader ( b ) ; const opCode = buf . uint8 ( ) ; if ( opCode !== OP_RETURN ) { throw new Error ( sprintf_js_1 . sprintf ( 'Not an op return output : %02x' , opCode ) ) ; } const protocolId = isTest ? OpReturnMessage . TestProtocolID : OpReturnMessage . ProtocolID ; let size = ParsePushDataScript ( buf ) ; if ( size !== protocolId . length ) { throw new Error ( sprintf_js_1 . sprintf ( 'Push not correct size for protocol ID : %d != %d' , size , protocolId . length ) ) ; } const readProtocolId = buf . read ( size ) . toString ( 'ascii' ) ; if ( readProtocolId !== protocolId ) { throw new Error ( 'Invalid protocol ID:' + readProtocolId ) ; } size = ParsePushDataScript ( buf ) ; const version = buf . uint8 ( ) ; if ( version !== OpReturnMessage . Version ) { throw new Error ( sprintf_js_1 . sprintf ( 'Unsupported version : %02x' , version ) ) ; } const code = buf . read ( 2 ) . toString ( 'ascii' ) ; const msg = actions_1 . TypeMapping ( code ) ; if ( ! msg ) { throw new Error ( sprintf_js_1 . sprintf ( 'Unknown code : %s' , code ) ) ; } msg . write ( buf . read ( size - 3 ) ) ; return msg ; }
Deserialize returns a message, as an OpReturnMessage, from the OP_RETURN script.
Deserialize returns a message as an OpReturnMessage from the OP_RETURN script .
// Parse OP_RETURN op code // Parse protocol ID // Parse push op code for payload length + 3 for version and message type code // if uint64(buf.Len()) < payloadSize { // 	return nil, sprintf('Payload push op code is too large for message : %d', payloadSize) // } // Parse version // Parse message type code