本文整理匯總了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
}
};
}
示例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);
}
示例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
};
}
示例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 };
}
示例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)
);
}
示例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
};
}
示例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)
);
}
示例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)
);
}
示例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)
);
}
示例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);
}
示例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
};
}
示例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
});
//.........這裏部分代碼省略.........