Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port latest changes from go-nitro till commit 7bea5bf on September 14 #126

Merged
merged 15 commits into from
Oct 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement checkForMissedEvents method
neerajvijay1997 committed Sep 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit a62fff7ad17a5bfcfe2d6acbb57547ef7ad3b654
26 changes: 0 additions & 26 deletions packages/nitro-node/src/internal/chain/chain.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import assert from 'assert';
import { providers } from 'ethers';

import { Address } from '../../types/types';
import { EthChainService } from '../../node/engine/chainservice/eth-chainservice';

export interface ChainOpts {
naAddress: Address
@@ -13,28 +12,3 @@ export interface ChainOpts {
chainUrl?: string
chainPk?: string
}

const log = debug('ts-nitro:chain');

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,
);
}
25 changes: 21 additions & 4 deletions packages/nitro-node/src/node/engine/chainservice/chainservice.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { ethers } from 'ethers';

import type { ReadChannel } from '@cerc-io/ts-channel';

import { Uint64 } from '@cerc-io/nitro-util';
import { Uint64, Uint } from '@cerc-io/nitro-util';
import { Bytes32 } from '@cerc-io/nitro-protocol';

import { ChainTransaction, Objective } from '../../../protocols/interfaces';
@@ -17,11 +17,13 @@ import { SignedState } from '../../../channel/state/signedstate';
export interface ChainEvent {
channelID(): Destination
blockNum(): Uint64
txIndex(): Uint
}

interface CommonEventConstructorOptions {
_channelID?: Destination
_blockNum?: Uint64
_txIndex?: Uint
}

// CommonEvent declares fields shared by all chain events
@@ -30,6 +32,8 @@ class CommonEvent implements ChainEvent {

_blockNum = BigInt(0);

_txIndex = BigInt(0);

constructor(params: CommonEventConstructorOptions) {
Object.assign(this, params);
}
@@ -41,6 +45,10 @@ class CommonEvent implements ChainEvent {
blockNum(): Uint64 {
return this._blockNum;
}

txIndex(): Uint {
return this._txIndex;
}
}

interface AssetAndAmountConstructorOptions {
@@ -78,13 +86,20 @@ export class DepositedEvent extends CommonEvent {
Object.assign(this, params);
}

static newDepositedEvent(channelId: Destination, blockNum: Uint64, assetAddress: Address, nowHeld?: bigint): DepositedEvent {
static newDepositedEvent(
channelId: Destination,
blockNum: Uint64,
txIndex: Uint64,
assetAddress: Address,
nowHeld?: bigint,
): DepositedEvent {
return new DepositedEvent(
{
nowHeld,
asset: assetAddress,
_channelID: channelId,
_blockNum: blockNum,
_txIndex: txIndex,
},
);
}
@@ -140,12 +155,14 @@ export class ChallengeRegisteredEvent extends CommonEvent {
static NewChallengeRegisteredEvent(
channelId: Destination,
blockNum: Uint64,
txIndex: Uint64,
variablePart: VariablePart,
sigs: Signature[],
): ChallengeRegisteredEvent {
return new ChallengeRegisteredEvent({
_channelID: channelId,
_blockNum: blockNum,
_txIndex: txIndex,
canditate: new VariablePart({
appData: variablePart.appData,
outcome: variablePart.outcome,
@@ -193,8 +210,8 @@ export class AllocationUpdatedEvent extends CommonEvent {
return `Channel ${this.channelID().string()} has had allocation updated to ${this.assetAndAmount.string()} at Block ${this._blockNum}`;
}

static newAllocationUpdatedEvent(channelId: Destination, blockNum: Uint64, assetAddress: Address, assetAmount: bigint | undefined): AllocationUpdatedEvent {
return new AllocationUpdatedEvent({ _channelID: channelId, _blockNum: blockNum }, { assetAddress, assetAmount });
static newAllocationUpdatedEvent(channelId: Destination, blockNum: Uint64, txIndex: Uint64, assetAddress: Address, assetAmount: bigint | undefined): AllocationUpdatedEvent {
return new AllocationUpdatedEvent({ _channelID: channelId, _blockNum: blockNum, _txIndex: txIndex }, { assetAddress, assetAmount });
}

constructor(
Loading