src/encoder.js
function writeAttenuationScript(attenuation_string, from_tx, from_index, address, buffer, offset) {
    let attenuation_buffer = Buffer.from(attenuation_string.toString('hex'));
    offset += bufferutils.writeVarInt(buffer, 26 + attenuation_string.length + 40, offset);
    offset = buffer.writeUInt8(77, offset);
    offset = buffer.writeInt16LE(attenuation_string.length, offset);
    offset += attenuation_buffer.copy(buffer, offset);
    offset = buffer.writeUInt8(36, offset);
    let hash = Buffer.from((from_tx != undefined) ? from_tx : '0000000000000000000000000000000000000000000000000000000000000000', 'hex').reverse();
    let index = Buffer.from('ffffffff', 'hex');
    if (from_index != undefined)
        index.writeInt32LE(from_index, 0);
    offset += Buffer.concat([hash, index]).copy(buffer, offset);
    offset = buffer.writeUInt8(178, offset);
    offset = buffer.writeUInt8(OPS.OP_DUP, offset);
    offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
    //Write previous output address
    offset = buffer.writeUInt8(20, offset); //Address length
    offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
    //Static transfer stuff
    offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
    offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
    return offset;
}
function writeAttenuationScript(attenuation_string, from_tx, from_index, address, buffer, offset) {
    let attenuation_buffer = Buffer.from(attenuation_string.toString('hex'));
    offset += bufferutils.writeVarInt(buffer, 26 + attenuation_string.length + 40, offset);
    offset = buffer.writeUInt8(77, offset);
    offset = buffer.writeInt16LE(attenuation_string.length, offset);
    offset += attenuation_buffer.copy(buffer, offset);
    offset = buffer.writeUInt8(36, offset);
    let hash = Buffer.from((from_tx != undefined) ? from_tx : '0000000000000000000000000000000000000000000000000000000000000000', 'hex').reverse();
    let index = Buffer.from('ffffffff', 'hex');
    if (from_index != undefined)
        index.writeInt32LE(from_index, 0);
    offset += Buffer.concat([hash, index]).copy(buffer, offset);
    offset = buffer.writeUInt8(178, offset);
    offset = buffer.writeUInt8(OPS.OP_DUP, offset);
    offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
    //Write previous output address
    offset = buffer.writeUInt8(20, offset); //Address length
    offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
    //Static transfer stuff
    offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
    offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
    return offset;
}
function writeAttenuationScript ( attenuation_string , from_tx , from_index , address , buffer , offset ) { let attenuation_buffer = Buffer . from ( attenuation_string . toString ( 'hex' ) ) ; offset += bufferutils . writeVarInt ( buffer , 26 + attenuation_string . length + 40 , offset ) ; offset = buffer . writeUInt8 ( 77 , offset ) ; offset = buffer . writeInt16LE ( attenuation_string . length , offset ) ; offset += attenuation_buffer . copy ( buffer , offset ) ; offset = buffer . writeUInt8 ( 36 , offset ) ; let hash = Buffer . from ( ( from_tx != undefined ) ? from_tx : '0000000000000000000000000000000000000000000000000000000000000000' , 'hex' ) . reverse ( ) ; let index = Buffer . from ( 'ffffffff' , 'hex' ) ; if ( from_index != undefined ) index . writeInt32LE ( from_index , 0 ) ; offset += Buffer . concat ( [ hash , index ] ) . copy ( buffer , offset ) ; offset = buffer . writeUInt8 ( 178 , offset ) ; offset = buffer . writeUInt8 ( OPS . OP_DUP , offset ) ; offset = buffer . writeUInt8 ( OPS . OP_HASH160 , offset ) ; //Write previous output address offset = buffer . writeUInt8 ( 20 , offset ) ; //Address length offset += Buffer . from ( base58check . decode ( address , 'hex' ) . data , 'hex' ) . copy ( buffer , offset ) ; //Static transfer stuff offset = buffer . writeUInt8 ( OPS . OP_EQUALVERIFY , offset ) ; offset = buffer . writeUInt8 ( OPS . OP_CHECKSIG , offset ) ; return offset ; }
Write p2pkh attenuation script to the given buffer.
@param {String} attenuation_string
@param {String} from_tx
@param {number} index
@param {String} address
@param {Buffer} buffer
@param {Number} offset
@returns {Number} new offset
Write p2pkh attenuation script to the given buffer .