dplatformos-transactionparser

解析交易

Usage no npm install needed!

<script type="module">
  import dplatformosTransactionparser from 'https://cdn.skypack.dev/dplatformos-transactionparser';
</script>

README

解析交易的行为和含义

使用方法:

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')
// execerName -> 购票
// action -> {"name":"挖矿","amount":1800000000,"coin":"BTY"}
// 解析交易内容并以字符串形式输出

var words = txInWords(execer, payload, 'cn')
// words -> '购票 {"name":"挖矿","amount":1800000000,"coin":"BTY"}'

6.0.2开始 转账的相关交易中note字段底层在处理时会以 byte[] 形式储存

展示时一般需要转换为utf8

parseTransferNote('0xe5ae89e585a8e694afe587bae8b4b9e794a83a20313030303030')
// 安全支出费用: 100000

tools.ts 中提供了各种格式字符串的转换

//  16进制字符串转unicode字符串
var hex2str = hex2str(hex)
//  unicode字符串转16进制字符串
var str2hex = str2hex(str)
// ... 等等 详情参见tools.ts