-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port latest changes from go-nitro till commit
7bea5bf
on September …
…14 (#126) * Implement checkForMissedEvents method * Implement Ticker class and add unit test * Refactor lastBlockNumSeen methods of memstore * Add isNewChainEvent check in updateWithChainEvent * Handle lastBlockNum in engine * Set initial value of lastChainUpdate property * Add chainStartBlock param to setupNode * Handle lastBlockNumSeen in durable store * Use @statechannels/nitro-protocol verion 2.0.0-alpha.5 * Use @cerc-io/peer version 0.2.60 * Refactor newEthChainServiceWithProvider * Implement method to print nested error logs * Refactor WrappedError to print nested errors * Handle review comments * Use constant LEVEL_NOT_FOUND --------- Co-authored-by: neeraj <[email protected]>
- Loading branch information
1 parent
9ea5521
commit d675a0d
Showing
40 changed files
with
573 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,51 @@ | ||
import debug from 'debug'; | ||
import assert from 'assert'; | ||
import { providers } from 'ethers'; | ||
import { | ||
BytesLike, ContractFactory, ContractInterface, Signer, ethers, providers, | ||
} from 'ethers'; | ||
|
||
import nitroAdjudicatorArtifact from '@statechannels/nitro-protocol/dist/artifacts/contracts/NitroAdjudicator.sol/NitroAdjudicator.json'; | ||
import consensusAppArtifact from '@statechannels/nitro-protocol/dist/artifacts/contracts/ConsensusApp.sol/ConsensusApp.json'; | ||
import virtualPaymentAppArtifact from '@statechannels/nitro-protocol/dist/artifacts/contracts/VirtualPaymentApp.sol/VirtualPaymentApp.json'; | ||
import { Uint64 } from '@cerc-io/nitro-util'; | ||
|
||
import { Address } from '../../types/types'; | ||
import { EthChainService } from '../../node/engine/chainservice/eth-chainservice'; | ||
|
||
const log = debug('ts-nitro:chain'); | ||
|
||
export interface ChainOpts { | ||
chainUrl?: string | ||
chainStartBlock: Uint64 | ||
chainPk?: string | ||
provider?: providers.JsonRpcProvider, | ||
naAddress: Address | ||
vpaAddress: Address | ||
caAddress: Address | ||
provider?: providers.JsonRpcProvider, | ||
chainUrl?: string | ||
chainPk?: string | ||
} | ||
|
||
const log = debug('ts-nitro:chain'); | ||
// deployContract deploys a contract and waits for the transaction to be mined. | ||
async function deployContract(name: string, signer: Signer, contractInterface: ContractInterface, bytecode: BytesLike): Promise<string> { | ||
const contractFactory = new ContractFactory(contractInterface, bytecode).connect(signer); | ||
|
||
const contract = await contractFactory.deploy(); | ||
log(`Waiting for ${name} deployment confirmation`); | ||
|
||
await contract.deployTransaction.wait(); | ||
log(`${name} successfully deployed to ${contract.address}`); | ||
|
||
return contract.address; | ||
} | ||
|
||
// DeployContracts deploys the NitroAdjudicator, VirtualPaymentApp and ConsensusApp contracts. | ||
export async function deployContracts(chainURL: string, chainPK?: string): Promise<[string, string, string]> { | ||
const provider = new providers.JsonRpcProvider(chainURL); | ||
const signer = chainPK ? new ethers.Wallet(chainPK, provider) : provider.getSigner(); | ||
|
||
const na = await deployContract('NitroAdjudicator', signer, nitroAdjudicatorArtifact.abi, nitroAdjudicatorArtifact.bytecode); | ||
|
||
const vpa = await deployContract('VirtualPaymentApp', signer, virtualPaymentAppArtifact.abi, virtualPaymentAppArtifact.bytecode); | ||
|
||
const ca = await deployContract('ConsensusApp', signer, consensusAppArtifact.abi, consensusAppArtifact.bytecode); | ||
|
||
export async function initializeEthChainService(chainOpts: ChainOpts): Promise<EthChainService> { | ||
if (chainOpts.provider) { | ||
log(`Initializing chain service and connecting to ${chainOpts.provider.connection.url}...`); | ||
|
||
return EthChainService.newEthChainServiceWithProvider( | ||
chainOpts.provider, | ||
chainOpts.naAddress, | ||
chainOpts.caAddress, | ||
chainOpts.vpaAddress, | ||
); | ||
} | ||
|
||
assert(chainOpts.chainUrl && chainOpts.chainPk); | ||
log(`Initializing chain service and connecting to ${chainOpts.chainUrl}...`); | ||
return EthChainService.newEthChainService( | ||
chainOpts.chainUrl, | ||
chainOpts.chainPk, | ||
chainOpts.naAddress, | ||
chainOpts.caAddress, | ||
chainOpts.vpaAddress, | ||
); | ||
return [na, vpa, ca]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.