import { System, Protobuf, StringBytes } from "@koinos/sdk-as"; import { textparserlib } from "./proto/textparserlib"; export class TextParserLib { _contractId: Uint8Array; /** * Create an instance of a TextParserLib contract * @example * ```ts * const contract = new TextParserLib(Base58.decode("1DQzuCcTKacbs9GGScFTU1Hc8BsyARTPqe")); * ``` */ constructor(contractId: Uint8Array) { this._contractId = contractId; } /** * Enconde a plain text message * @external * @readonly */ parse_message(args: textparserlib.parse_message_args): textparserlib.parse_message_result { const argsBuffer = Protobuf.encode(args, textparserlib.parse_message_args.encode); const callRes = System.call(this._contractId, 0x6a5adba6, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'TextParserLib.parse_message': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new textparserlib.parse_message_result(); return Protobuf.decode(callRes.res.object, textparserlib.parse_message_result.decode); } }