def __init__(self): """ keystore对照表: tx_keystore : 59514f8d87c964520fcaf515d300e3f704bf6fcb """ self.tx_keystore = "59514f8d87c964520fcaf515d300e3f704bf6fcb" self.ctx = ska.Ska(EC_256R1)
def deal_transaction(self, json_data): """ 交易接口的请求数据处理 """ ctx = ska.Ska(EC_256R1) json_path = os.path.join( os.path.split(os.path.realpath(__file__))[0], 'keystore1.json') kp = tx_helper.loadkeystore(ctx, json_path) print(kp) print("1111111111111") # 截取想要的数据段 my_dict = { key: value for key, value in json_data.items() if key is "transaction" } print(my_dict) print("22222222222222") # 对单引号进行匹配转换 send_data = re.sub("'", "\"", str(my_dict)) print(send_data) req = json_format.Parse( send_data, tximpl_pb2.MultiTransactionImpl()) # MultiTransactionImpl print("33333333333333") print("create multi transaction", req) tx = tx_helper.impl2tx(req) tx.txBody.ClearField("signatures") print("multi transaction", tx) bodyBytes = tx.txBody.SerializeToString() with ctx.txn() as txn: sign = tx.txBody.signatures.add() sign.signature = ctx.ecsign(txn, HASH_SHA256, SIGN_CWV, kp.pri(), bodyBytes) itx = tx_helper.tx2impl(tx) req.CopyFrom(itx) return json_format.MessageToJson(req)
import os, codecs import tx_helper from google.protobuf import json_format import tximpl_pb2 import tx_pb2 from ctypes import * import ska from ska_defines import * ctx = ska.Ska(EC_256R1) #TODO data may be not hex url_gtx = 'http://172.18.92.101:38000/cks/api/pbgtx.do' url_mtx = 'http://172.18.92.101:38000/cks/api/pbmtx.do' js = """ { "transaction": { "txBody": { "inputs": [ { "nonce": 2, "address": "59514f8d87c964520fcaf515d300e3f704bf6fcb", "amount": "100" } ], "outputs": [ { "address": "f192c303b6aac4b06ec8fae6473a98060fb7aaa3", "amount": "100" }