背景
区块链程序调式时希望把握运行状况,知道运行过程中每一步变量的变化。
办法
下面两个例子,分别表明了如何在后端RSH文件和前端JS文件中买入Log输出语句的方法
RSH
'reach 0.1';
'use strict';
export const main = Reach.App(() => {
const A = Participant('Alice', {
...hasConsoleLogger,
});
deploy();
A.interact.log(true);
A.interact.log(1);
A.interact.log([1, true]);
A.interact.log({x: 1, y: true});
A.interact.log(Maybe(UInt).Some(5));
exit();
});
JS(mjs)
import { loadStdlib } from '@reach-sh/stdlib';
import * as backend from './build/index.main.mjs';
(async () => {
const stdlib = await loadStdlib();
const startingBalance = stdlib.parseCurrency(10);
const accAlice = await stdlib.newTestAccount(startingBalance);
const ctcAlice = accAlice.deploy(backend);
await Promise.all([
backend.Alice(
ctcAlice,
{ ...stdlib.hasConsoleLogger },
),
]);
})();
|