当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ethers.utils.bigNumberify方法代码示例

本文整理汇总了TypeScript中ethers.ethers.utils.bigNumberify方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ethers.utils.bigNumberify方法的具体用法?TypeScript ethers.utils.bigNumberify怎么用?TypeScript ethers.utils.bigNumberify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ethers.ethers.utils的用法示例。


在下文中一共展示了ethers.utils.bigNumberify方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: propose

  public static propose(message: InternalMessage): StateProposal {
    const toAddress = message.clientMessage.toAddress;
    const fromAddress = message.clientMessage.fromAddress;

    const balances = cf.legacy.utils.PeerBalance.balances(
      toAddress,
      ethers.utils.bigNumberify(0),
      fromAddress,
      ethers.utils.bigNumberify(0)
    );
    const localNonce = 0;
    const freeBalance = new cf.legacy.utils.FreeBalance(
      balances.peerA.address,
      balances.peerA.balance,
      balances.peerB.address,
      balances.peerB.balance,
      FREE_BALANCE_UNIQUE_ID,
      localNonce,
      FREE_BALANCE_TIMEOUT,
      new cf.legacy.utils.Nonce(false, FREE_BALANCE_UNIQUE_ID, 0)
    );
    const stateChannel = new StateChannelInfoImpl(
      toAddress,
      fromAddress,
      message.clientMessage.multisigAddress,
      {},
      freeBalance
    );
    return {
      state: {
        [String(message.clientMessage.multisigAddress)]: stateChannel
      }
    };
  }
开发者ID:cylof22,项目名称:monorepo,代码行数:34,代码来源:setup-proposer.ts

示例2: validateInstallInfos

function validateInstallInfos(
  infos: cf.legacy.channel.StateChannelInfos,
  expectedCfAddr: cf.legacy.utils.H256
) {
  const stateChannel = infos[UNUSED_FUNDED_ACCOUNT];

  expect(stateChannel.freeBalance.aliceBalance.toNumber()).toEqual(15);
  expect(stateChannel.freeBalance.bobBalance.toNumber()).toEqual(17);

  const app = infos[UNUSED_FUNDED_ACCOUNT].appInstances[expectedCfAddr];
  const expectedSalt =
    "0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6";

  expect(app.id).toEqual(expectedCfAddr);
  expect(app.peerA.address).toEqual(A_ADDRESS);
  expect(app.peerA.balance.toNumber()).toEqual(5);
  expect(app.peerB.address).toEqual(B_ADDRESS);
  expect(app.keyA).toEqual(KEY_A);
  expect(app.keyB).toEqual(KEY_B);
  expect(app.encodedState).toEqual("0x0");
  expect(app.localNonce).toEqual(1);
  expect(app.timeout).toEqual(100);
  expect(app.terms.assetType).toEqual(0);
  expect(app.terms.limit).toEqual(ethers.utils.bigNumberify(8));
  expect(app.terms.token).toEqual(TOKEN_ADDRESS);
  expect(app.cfApp.address).toEqual(APP_ADDRESS);
  expect(app.cfApp.applyAction).toEqual(APPLY_ACTION);
  expect(app.cfApp.resolve).toEqual(RESOLVE);
  expect(app.cfApp.getTurnTaker).toEqual(TURN);
  expect(app.cfApp.isStateTerminal).toEqual(IS_STATE_TERMINAL);
  expect(app.dependencyNonce.salt).toEqual(expectedSalt);
  expect(app.dependencyNonce.nonceValue).toEqual(0);
}
开发者ID:cylof22,项目名称:monorepo,代码行数:33,代码来源:state-transition.spec.ts

示例3: installClientMsg

function installClientMsg(): cf.legacy.node.ClientActionMessage {
  return {
    requestId: "0",
    appId: "0",
    action: cf.legacy.node.ActionName.INSTALL,
    data: {
      peerA: new cf.legacy.utils.PeerBalance(A_ADDRESS, 5),
      peerB: new cf.legacy.utils.PeerBalance(B_ADDRESS, 3),
      keyA: KEY_A,
      keyB: KEY_B,
      encodedAppState: "0x0",
      terms: new cf.legacy.app.Terms(
        0,
        ethers.utils.bigNumberify(8),
        TOKEN_ADDRESS
      ),
      app: new cf.legacy.app.AppInterface(
        APP_ADDRESS,
        APPLY_ACTION,
        RESOLVE,
        TURN,
        IS_STATE_TERMINAL,
        ABI_ENCODING
      ),
      timeout: 100
    },
    multisigAddress: UNUSED_FUNDED_ACCOUNT,
    fromAddress: B_ADDRESS,
    toAddress: A_ADDRESS,
    stateChannel: undefined,
    seq: 0
  };
}
开发者ID:cylof22,项目名称:monorepo,代码行数:33,代码来源:state-transition.spec.ts

示例4: makeDeposits

async function makeDeposits(
  multisigAddr: string,
  walletA: TestResponseSink,
  walletB: TestResponseSink,
  depositAmount: ethers.utils.BigNumber
): Promise<{
  cfAddr: string;
  txFeeA: ethers.utils.BigNumber;
  txFeeB: ethers.utils.BigNumber;
}> {
  const { txFee: txFeeA } = await deposit(
    multisigAddr,
    walletA, // depositor
    walletB, // counterparty
    depositAmount, // amountToDeposit
    ethers.utils.bigNumberify(0) // counterpartyBalance
  );
  const { cfAddr, txFee: txFeeB } = await deposit(
    multisigAddr,
    walletB, // depositor
    walletA, // counterparty
    depositAmount, // amountToDeposit
    depositAmount // counterpartyBalance
  );
  return { cfAddr, txFeeA, txFeeB };
}
开发者ID:cylof22,项目名称:monorepo,代码行数:26,代码来源:cf-operations.spec.ts

示例5: makeDeposits

 public static async makeDeposits(
   peerA: TestResponseSink,
   peerB: TestResponseSink
 ): Promise<any> {
   await Depositor.deposit(
     peerA,
     peerB,
     ethers.utils.bigNumberify(10),
     ethers.utils.bigNumberify(0)
   );
   await Depositor.deposit(
     peerB,
     peerA,
     ethers.utils.bigNumberify(5),
     ethers.utils.bigNumberify(10)
   );
 }
开发者ID:cylof22,项目名称:monorepo,代码行数:17,代码来源:lifecycle.spec.ts

示例6: startInstallBalanceRefundMsg

 public static startInstallBalanceRefundMsg(
   from: string,
   to: string,
   threshold: ethers.utils.BigNumber
 ): cf.legacy.node.ClientActionMessage {
   const canon = cf.legacy.utils.PeerBalance.balances(
     from,
     ethers.utils.bigNumberify(0),
     to,
     ethers.utils.bigNumberify(0)
   );
   const terms = new cf.legacy.app.Terms(
     0,
     new ethers.utils.BigNumber(10),
     ethers.constants.AddressZero
   ); // TODO:
   const app = new cf.legacy.app.AppInterface(
     "0x0",
     "0x11111111",
     "0x11111111",
     "0x11111111",
     "0x11111111",
     ""
   ); // TODO:
   const timeout = 100;
   const installData: cf.legacy.app.InstallData = {
     terms,
     app,
     timeout,
     peerA: canon.peerA,
     peerB: canon.peerB,
     keyA: from,
     keyB: to,
     encodedAppState: "0x1234"
   };
   return {
     requestId: "1",
     appId: "",
     action: cf.legacy.node.ActionName.INSTALL,
     data: installData,
     multisigAddress: UNUSED_FUNDED_ACCOUNT,
     toAddress: to,
     fromAddress: from,
     seq: 0
   };
 }
开发者ID:cylof22,项目名称:monorepo,代码行数:46,代码来源:lifecycle.spec.ts

示例7: validatePostsetup

 /**
  * Asserts the setup protocol modifies the internally stored state correctly.
  */
 public static validatePostsetup(
   peerA: TestResponseSink,
   peerB: TestResponseSink
 ) {
   SetupProtocol.validateWallet(
     peerA,
     peerB,
     ethers.utils.bigNumberify(0),
     ethers.utils.bigNumberify(0)
   );
   SetupProtocol.validateWallet(
     peerB,
     peerA,
     ethers.utils.bigNumberify(0),
     ethers.utils.bigNumberify(0)
   );
 }
开发者ID:cylof22,项目名称:monorepo,代码行数:20,代码来源:setup-protocol.ts

示例8: validateSetup

function validateSetup(
  multisigAddr: string,
  walletA: TestResponseSink,
  walletB: TestResponseSink
) {
  validateNoAppsAndFreeBalance(
    multisigAddr,
    walletA,
    walletB,
    ethers.utils.bigNumberify(0),
    ethers.utils.bigNumberify(0)
  );
  validateNoAppsAndFreeBalance(
    multisigAddr,
    walletB,
    walletA,
    ethers.utils.bigNumberify(0),
    ethers.utils.bigNumberify(0)
  );
}
开发者ID:cylof22,项目名称:monorepo,代码行数:20,代码来源:cf-operations.spec.ts

示例9: uninstall

 public static async uninstall(
   peerA: TestResponseSink,
   peerB: TestResponseSink,
   cfAddr: string
 ) {
   const msg = TicTacToeSimulator.uninstallStartMsg(
     cfAddr,
     peerA.signingKey.address!,
     ethers.utils.bigNumberify(4),
     peerB.signingKey.address!,
     ethers.utils.bigNumberify(0)
   );
   const response = await peerA.runProtocol(msg);
   expect(response.status).toEqual(cf.legacy.node.ResponseStatus.COMPLETED);
   // A wins so give him 2 and subtract 2 from B
   TicTacToeSimulator.validateUninstall(
     cfAddr,
     peerA,
     ethers.utils.bigNumberify(12),
     ethers.utils.bigNumberify(3)
   );
   await cf.legacy.utils.sleep(50);
   TicTacToeSimulator.validateUninstall(
     cfAddr,
     peerB,
     ethers.utils.bigNumberify(12),
     ethers.utils.bigNumberify(3)
   );
 }
开发者ID:cylof22,项目名称:monorepo,代码行数:29,代码来源:lifecycle.spec.ts

示例10: setupInstallState

function setupInstallState(): Node {
  const freeBalance = new cf.legacy.utils.FreeBalance(
    A_ADDRESS,
    ethers.utils.bigNumberify(20),
    B_ADDRESS,
    ethers.utils.bigNumberify(20),
    0, // local nonce
    0, // uniqueId
    100, // timeout
    new cf.legacy.utils.Nonce(true, 0, 0) // nonce
  );
  const info = new StateChannelInfoImpl(
    B_ADDRESS,
    A_ADDRESS,
    UNUSED_FUNDED_ACCOUNT,
    {},
    freeBalance
  );
  const channelStates: cf.legacy.channel.StateChannelInfos = {
    [UNUSED_FUNDED_ACCOUNT]: info
  };
  return new Node(channelStates, cf.legacy.network.EMPTY_NETWORK_CONTEXT);
}
开发者ID:cylof22,项目名称:monorepo,代码行数:23,代码来源:state-transition.spec.ts

示例11: startInstallBalanceRefundMsg

function startInstallBalanceRefundMsg(
  multisigAddr: string,
  from: string,
  to: string,
  threshold: ethers.utils.BigNumber
): cf.legacy.node.ClientActionMessage {
  let peerA = from;
  let peerB = to;
  if (peerB.localeCompare(peerA) < 0) {
    const tmp = peerA;
    peerA = peerB;
    peerB = tmp;
  }
  const terms = new cf.legacy.app.Terms(
    0,
    ethers.utils.bigNumberify(10),
    ethers.constants.AddressZero
  ); // todo

  const app = new cf.legacy.app.AppInterface(
    "0x0",
    "0x00000000",
    "0x00000000",
    "0x00000000",
    "0x00000000",
    ""
  ); // todo
  const timeout = 100;
  const installData: cf.legacy.app.InstallData = {
    terms,
    app,
    timeout,
    peerA: new cf.legacy.utils.PeerBalance(peerA, 0),
    peerB: new cf.legacy.utils.PeerBalance(peerB, 0),
    keyA: peerA,
    keyB: peerB,
    encodedAppState: "0x1234"
  };
  return {
    requestId: "1",
    appId: "",
    action: cf.legacy.node.ActionName.INSTALL,
    data: installData,
    multisigAddress: multisigAddr,
    toAddress: to,
    fromAddress: from,
    seq: 0
  };
}
开发者ID:cylof22,项目名称:monorepo,代码行数:49,代码来源:cf-operations.spec.ts

示例12: it

  it("should have the correct funds on chain", async () => {
    const depositAmount = ethers.utils.parseEther("0.0005");

    const walletA = new TestResponseSink(
      A_PRIVATE_KEY,
      devEnvNetworkContext7777777
    );
    const walletB = new TestResponseSink(
      B_PRIVATE_KEY,
      devEnvNetworkContext7777777
    );

    const startingBalanceA = await ganache.getBalance(A_ADDRESS);
    const startingBalanceB = await ganache.getBalance(B_ADDRESS);

    const ethersMasterWallet = new ethers.Wallet(
      UNUSED_FUNDED_ACCOUNT_PRIVATE_KEY,
      ganache
    );

    walletA.io.peer = walletB;
    walletB.io.peer = walletA;

    const peerBalances = cf.legacy.utils.PeerBalance.balances(
      A_ADDRESS,
      ethers.utils.bigNumberify(0),
      B_ADDRESS,
      ethers.utils.bigNumberify(0)
    );

    const signingKeys = [
      peerBalances.peerA.address,
      peerBalances.peerB.address
    ];

    const registry = await new ethers.Contract(
      devEnvNetworkContext7777777.registryAddr,
      RegistryJson.abi,
      ethersMasterWallet
    );

    // TODO: Truffle migrate does not auto-link the bytecode in the build folder,
    //       so we have to do it manually. Will fix later of course :)
    // https://github.com/counterfactual/monorepo/issues/113
    const multisig = await new ethers.ContractFactory(
      MinimumViableMultisigJson.abi,
      devEnvNetworkContext7777777.linkedBytecode(
        MinimumViableMultisigJson.bytecode
      ),
      ethersMasterWallet
    ).deploy();

    await multisig.functions.setup(signingKeys);

    await setup(multisig.address, walletA, walletB);

    const {
      cfAddr: balanceRefundAppId,
      txFeeA: depositTxFeeA,
      txFeeB: depositTxFeeB
    } = await makeDeposits(multisig.address, walletA, walletB, depositAmount);

    const app = cf.legacy.utils.FreeBalance.contractInterface(
      devEnvNetworkContext7777777
    );

    const terms = cf.legacy.utils.FreeBalance.terms();

    const initcode = new ethers.utils.Interface(
      AppInstanceJson.abi
    ).deployFunction.encode(
      devEnvNetworkContext7777777.linkedBytecode(AppInstanceJson.bytecode),
      [
        multisig.address,
        signingKeys,
        app.hash(),
        terms.hash(),
        // TODO: Don't hard-code the timeout, make it dependant on some
        // function(blockchain) to in the future check for congestion... :)
        // https://github.com/counterfactual/monorepo/issues/112
        100
      ]
    );

    // TODO: Figure out how to not have to put the insanely high gasLimit here
    // https://github.com/counterfactual/monorepo/issues/146
    await registry.functions.deploy(initcode, 0, { gasLimit: 6e9 });

    const uninstallTx: Transaction = await walletA.store.getTransaction(
      balanceRefundAppId,
      cf.legacy.node.ActionName.UNINSTALL
    );

    await ethersMasterWallet.sendTransaction({
      to: uninstallTx.to,
      value: `0x${uninstallTx.value.toString(16)}`,
      data: uninstallTx.data,
      gasLimit: 6e9
    });

//.........这里部分代码省略.........
开发者ID:cylof22,项目名称:monorepo,代码行数:101,代码来源:cf-operations.spec.ts


注:本文中的ethers.ethers.utils.bigNumberify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。