UNPKG

@roochnetwork/rooch-sdk

Version:
97 lines (96 loc) 3.11 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var transactionData_exports = {}; __export(transactionData_exports, { CallFunction: () => CallFunction, MoveAction: () => MoveAction, TransactionData: () => TransactionData }); module.exports = __toCommonJS(transactionData_exports); var import_utils = require("../utils/index.js"); var import_address = require("../address/index.js"); var import_bcs = require("../bcs/index.js"); class CallFunction { constructor(input) { const [pkg, mod, fn] = "target" in input ? input.target.split("::") : [input.address, input.module, input.function]; this.address = pkg; this.module = mod; this.function = fn; this.args = input.args || []; this.typeArgs = input.typeArgs?.map((item) => import_bcs.Serializer.typeTagToString(item)) || []; } functionId() { return `${(0, import_address.normalizeRoochAddress)(this.address)}::${this.module}::${this.function}`; } encodeArgs() { return this.args?.map((item) => item.encodeWithHex()); } encodeArgsWithUtf8() { return ""; } encodeArgsToByteArrays() { return this.args.map((item) => item.encode()).map((item) => Array.from(item)); } } class MoveAction { constructor(scheme, val) { this.scheme = scheme; this.val = val; } static newCallFunction(input) { return new MoveAction(1, new CallFunction(input)); } static newCallScript(input) { return new MoveAction(2, input); } } class TransactionData { constructor(action, maxGas, sender, sequenceNumber, chainId) { this.sender = sender; this.sequenceNumber = sequenceNumber; this.chainId = chainId; this.action = action; this.maxGas = maxGas; } encode() { const call = this.action.val; return import_bcs.bcs.RoochTransactionData.serialize({ sender: this.sender, sequenceNumber: this.sequenceNumber, chainId: this.chainId, maxGas: this.maxGas, action: { kind: "CallFunction", functionId: { moduleId: { address: call.address, name: call.module }, name: call.function }, args: Array.from(call.encodeArgsToByteArrays()), typeArgs: call.typeArgs } }); } hash() { return (0, import_utils.sha3_256)(this.encode().toBytes()); } } //# sourceMappingURL=transactionData.js.map