区块链-Reach:如何在Reach和前端JS中埋Log

背景

区块链程序调式时希望把握运行状况,知道运行过程中每一步变量的变化。

办法

下面两个例子,分别表明了如何在后端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 },
    ),
  ]);
})();

猜你喜欢

转载自blog.csdn.net/weixin_41697242/article/details/120194356