UNPKG

meta-contract

Version:

Meta Contract SDK

36 lines (35 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.newDataPart = void 0; const TokenUtil = require("../../common/tokenUtil"); const NFT_ID_LEN = 36; const NFT_CODE_HASH_LEN = 20; const NFT_ID_OFFSET = 0 + NFT_ID_LEN; const NFT_CODE_HASH_OFFSET = NFT_ID_OFFSET + NFT_CODE_HASH_LEN; function newDataPart(dataPart) { let inputTokenIndexArrayBuf = Buffer.alloc(0); dataPart.inputTokenIndexArray.forEach((tokenIndex) => { inputTokenIndexArrayBuf = Buffer.concat([ inputTokenIndexArrayBuf, TokenUtil.getUInt32Buf(tokenIndex), ]); }); let receiverArrayBuf = Buffer.alloc(0); dataPart.receiverArray.map((address) => { receiverArrayBuf = Buffer.concat([receiverArrayBuf, address.hashBuffer]); }); let nSenderBuf = TokenUtil.getUInt32Buf(dataPart.nSender); let nReceiversBuf = TokenUtil.getUInt32Buf(dataPart.nReceivers); let tokenCodeHashBuf = Buffer.from(dataPart.tokenCodeHash, 'hex'); let tokenIDBuf = Buffer.from(dataPart.tokenID, 'hex'); const buf = Buffer.concat([ inputTokenIndexArrayBuf, nSenderBuf, receiverArrayBuf, nReceiversBuf, tokenCodeHashBuf, tokenIDBuf, ]); return TokenUtil.buildScriptData(buf); } exports.newDataPart = newDataPart;