解析交易的行为和含义
使用方法:
npm install @33cn/chain33-transaction-parser
import { txParser, txInWords, parseTransferNote } from '@33cn/chain33-transaction-parser'
确定交易的含义,主要由执行器execer的类别,以及传参payload来确定
txmap.ts 文件中包含对execer的翻译以及payload中代表价值的字段判断
栗子
const execer = 'ticket'
const payload = {
"miner": {
"bits": 508549505,
"reward": "1800000000",
"ticketId": "1bgg6HwQretMiVcSWvayPRvVtwjyKfz1J:0x5b7a322ab74e65d7482ad1d6877a23de98e0f6b5c15d5d92bb3dcbfed5be89f5:0000000000",
"modify": "0x307837306161376436623761326335646362376366643438316464383065663838323437616338656564326135383233636139613862663763633562376238633130",
"privHash": null
},
"ty": 16
}
const { execerName, action } = txParser(execer, payload, 'cn')
var words = txInWords(execer, payload, 'cn')
6.0.2开始 转账的相关交易中note字段底层在处理时会以 byte[] 形式储存
展示时一般需要转换为utf8
parseTransferNote('0xe5ae89e585a8e694afe587bae8b4b9e794a83a20313030303030')
tools.ts 中提供了各种格式字符串的转换
var hex2str = hex2str(hex)
var str2hex = str2hex(str)