@Description("这是调用BDLedger的示例合约") @Permission("Ledger") contract LedgerExample{ //{"ip":"39.108.56.240","port":18091} function onCreate(){ var arg = { "ip":"39.108.56.240","port":18091}; Global.client = LedgerUtil.getClient(arg); } @Description("参数示例:{\"ip\":\"39.108.56.240\",\"port\":18091}") export function connect(arg){ arg = JSON.parse(arg); Global.client = LedgerUtil.getClient(arg); return Global.client.clientVersionSync().getVersion(); } @Description("无需参数") export function getLedgers(arg){ return Global.client.getLedgersSync().toString(); } @Description("参数为账本名称") export function createLedgers(arg){ return Global.client.createLedgerSync(arg); } //{"ledger":"testCHQ","from":"0123456789012345678901234567890123456789","to":"0123456789012345678901234567890123456789","data":"hello"} @Description("参数示例:{\"ledger\":\"testCHQ\",\"from\":\"0123456789012345678901234567890123456789\",\"to\":\"0123456789012345678901234567890123456789\",\"data\":\"hello\"}") export function sendMessage(arg){ arg = JSON.parse(arg); var ret = LedgerUtil.sendMessage(Global.client,arg); return ret; } @Description("参数示例:{\"ledger\":\"testCHQ\",\"hash\":\"369b6a726e47b17caf53f19c24a18c25cfa3398a\"}") export function queryHash(arg){ arg = JSON.parse(arg); return JSON.stringify(LedgerUtil.queryByHash(Global.client,arg)); } //http形式调用:http://contract.internetapi.cn/SCIDE/CMManager?action=queryDataByHash&hash=xxxx //不加则为默认账本,也可加账本名作为参数:http://contract.internetapi.cn/SCIDE/CMManager?action=queryDataByHash&ledger=xxxx&hash=xxxx }