本文整理汇总了TypeScript中ethers.ethers.utils类的典型用法代码示例。如果您正苦于以下问题:TypeScript ethers.utils类的具体用法?TypeScript ethers.utils怎么用?TypeScript ethers.utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ethers.utils类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("transfers the funds conditionally if true", async () => {
const randomTarget = Utils.randomETHAddress();
const tx = ct.interface.functions.executeSimpleConditionalTransaction.encode(
[
makeCondition(ethers.constants.HashZero, true),
{
value: [Utils.UNIT_ETH],
assetType: 0,
to: [randomTarget],
token: ethers.constants.AddressZero,
data: []
}
]
);
await testDelegateProxy.functions.delegate(
ct.address,
tx,
Utils.HIGH_GAS_LIMIT
);
const balTarget = await provider.getBalance(randomTarget);
expect(balTarget.toHexString()).to.be.eql(
ethers.utils.hexStripZeros(Utils.UNIT_ETH.toHexString())
);
const emptyBalance = new ethers.utils.BigNumber(0);
const balDelegate = await provider.getBalance(testDelegateProxy.address);
expect(balDelegate.toHexString()).to.be.eql(
ethers.utils.hexStripZeros(emptyBalance.toHexString())
);
});
示例2:
const computeStateHash = (stateHash: string, nonce: number, timeout: number) =>
ethers.utils.keccak256(
ethers.utils.solidityPack(
["bytes1", "address[]", "uint256", "uint256", "bytes32"],
["0x19", [A.address, B.address], nonce, timeout, stateHash]
)
);
示例3: 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
}
};
}
示例4: signMessageBytes
export function signMessageBytes(message: string, wallet: ethers.Wallet) {
const [v, r, s] = signMessageVRS(message, wallet);
return (
ethers.utils.hexlify(ethers.utils.padZeros(r, 32)).substring(2) +
ethers.utils.hexlify(ethers.utils.padZeros(s, 32)).substring(2) +
v.toString(16)
);
}
示例5: it
it("reverts if the target is not a contract", async () => {
await Utils.assertRejects(
testCaller.functions.execStaticCall(
ethers.utils.hexlify(ethers.utils.randomBytes(20)),
echo.interface.functions.helloWorld.sighash,
"0x"
)
);
});
示例6: 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);
}
示例7: 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
};
}