agent-backend/contracts/LedgerExample/LedgerExample.yjs

39 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

2021-09-26 04:49:24 +00:00
@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
}