Skip to content

Commit

Permalink
Downgrade ethers to v5 for using in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed May 24, 2023
1 parent c189c1e commit 4ad0440
Show file tree
Hide file tree
Showing 16 changed files with 512 additions and 99 deletions.
1 change: 1 addition & 0 deletions packages/example-web-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@types/node": "^16.18.31",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"ethers": "^5.7.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@libp2p/tcp": "^7.0.1",
"@nodeguy/channel": "^1.0.2",
"debug": "^4.3.4",
"ethers": "^6.4.0",
"ethers": "^5.7.2",
"libp2p": "^0.45.3"
}
}
3 changes: 3 additions & 0 deletions packages/nitro-client/src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export { Client } from './client/client';
export { EthChainService } from './client/engine/chainservice/eth-chainservice';

export const test = (): string => {
// eslint-disable-next-line no-console
console.log('Test from nitro-client');
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro-client/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Client {
private vm: VoucherManager;

constructor(msg: MessageService, chain: ChainService, store: Store, policymaker: PolicyMaker) {
this.vm = new VoucherManager(ethers.ZeroAddress, store);
this.vm = new VoucherManager(ethers.constants.AddressZero, store);
this.engine = new Engine(this.vm, msg, chain, store, policymaker);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AddressLike } from 'ethers';
import type { ReadChannel } from '@nodeguy/channel';

import { ChainTransaction } from '../../../protocols/interfaces';
import { Address } from '../../../types/types';

// ChainEvent dictates which methods all chain events must implement
export interface ChainEvent {
Expand All @@ -17,9 +17,9 @@ export interface ChainService {
sendTransaction (tx: ChainTransaction): void;

// TODO: Use Address type
getConsensusAppAddress (): AddressLike;
getConsensusAppAddress (): Address;

getVirtualPaymentAppAddress (): AddressLike;
getVirtualPaymentAppAddress (): Address;

// TODO: Can throw an error
getChainId (): bigint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
AddressLike, Log, TransactionLike, ethers,
} from 'ethers';
import { ethers } from 'ethers';
import debug from 'debug';
import type { ReadChannel, ReadWriteChannel } from '@nodeguy/channel';

import { Log } from '@ethersproject/abstract-provider'
import { NitroAdjudicator } from './adjudicator/nitro-adjudicator';
import { ChainService, ChainEvent } from './chainservice';
import { ChainTransaction } from '../../../protocols/interfaces';
import { Address } from '../../../types/types';

interface EthChain {
// TODO: Extend bind.ContractBackend (github.com/ethereum/go-ethereum/accounts/abi/bind)
Expand All @@ -26,13 +26,13 @@ export class EthChainService implements ChainService {

private na: NitroAdjudicator;

private naAddress: AddressLike;
private naAddress: string;

private consensusAppAddress: AddressLike;
private consensusAppAddress: string;

private virtualPaymentAppAddress: AddressLike;
private virtualPaymentAppAddress: string;

private txSigner: TransactionLike;
private txSigner: ethers.Transaction;

private out: ReadWriteChannel<ChainEvent>;

Expand All @@ -45,10 +45,10 @@ export class EthChainService implements ChainService {
constructor(
chain: EthChain,
na: NitroAdjudicator,
naAddress: AddressLike,
consensusAppAddress: AddressLike,
virtualPaymentAppAddress: AddressLike,
txSigner: TransactionLike,
naAddress: string,
consensusAppAddress: string,
virtualPaymentAppAddress: string,
txSigner: ethers.Transaction,
out: ReadWriteChannel<ChainEvent>,
logger: debug.Debugger,
ctx: AbortController,
Expand All @@ -71,15 +71,15 @@ export class EthChainService implements ChainService {
static newEthChainService(
chainUrl: string,
chainPk: string,
naAddress: AddressLike,
caAddress: AddressLike,
vpaAddress: AddressLike,
naAddress: string,
caAddress: string,
vpaAddress: string,
logDestination: WritableStream,
): EthChainService | void {}

// defaultTxOpts returns transaction options suitable for most transaction submissions
// TODO: Implement and remove void
private defaultTxOpts(): TransactionLike | void {}
private defaultTxOpts(): ethers.Transaction | void {}

// sendTransaction sends the transaction and blocks until it has been submitted.
// TODO: Implement and remove void
Expand Down Expand Up @@ -109,13 +109,13 @@ export class EthChainService implements ChainService {
}

// TODO: Implement
getConsensusAppAddress(): AddressLike {
return ethers.ZeroAddress;
getConsensusAppAddress(): Address {
return ethers.constants.AddressZero;
}

// TODO: Implement
getVirtualPaymentAppAddress(): AddressLike {
return ethers.ZeroAddress;
getVirtualPaymentAppAddress(): Address {
return ethers.constants.AddressZero;
}

// TODO: Implement and remove void
Expand Down
12 changes: 7 additions & 5 deletions packages/nitro-client/src/client/engine/engine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddressLike, ethers } from 'ethers';
import { ethers } from 'ethers';
import createChannel from '@nodeguy/channel';
import type { ReadChannel, ReadWriteChannel } from '@nodeguy/channel';

Expand All @@ -12,6 +12,7 @@ import { Objective, ObjectiveRequest, SideEffects } from '../../protocols/interf
import { Message, ObjectiveId, ObjectivePayload } from '../../protocols/messages';
import { Objective as VirtualFundObjective } from '../../protocols/virtualfund/virtualfund';
import { Proposal } from '../../channel/consensus-channel/consensus-channel';
import { Address } from '../../types/types';

export type PaymentRequest = {
channelId: string
Expand Down Expand Up @@ -192,13 +193,14 @@ export class Engine {
}

// GetConsensusAppAddress returns the address of a deployed ConsensusApp (for ledger channels)
getConsensusAppAddress(): AddressLike {
return ethers.ZeroAddress;
getConsensusAppAddress(): Address {
ethers.utils.getAddress
return ethers.constants.AddressZero;
}

// GetVirtualPaymentAppAddress returns the address of a deployed VirtualPaymentApp
getVirtualPaymentAppAddress(): AddressLike {
return ethers.ZeroAddress;
getVirtualPaymentAppAddress(): Address {
return ethers.constants.AddressZero;
}

// logMessage logs a message to the engine's logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { Address } from '../../../../types/types';

const log = debug('ts-nitro:p2p-message-service');

const PROTOCOL_ID = '/ts-nitro/msg/1.0.0';
const PEER_EXCHANGE_PROTOCOL_ID = '/ts-nitro/peerinfo/1.0.0';
const PROTOCOL_ID = '/go-nitro/msg/1.0.0';
const PEER_EXCHANGE_PROTOCOL_ID = '/go-nitro/peerinfo/1.0.0';
const BUFFER_SIZE = 1_000;

// BasicPeerInfo contains the basic information about a peer
Expand Down
13 changes: 7 additions & 6 deletions packages/nitro-client/src/client/engine/store/memstore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddressLike, ethers } from 'ethers';
import { ethers } from 'ethers';

import { Store } from './store';
import { Objective } from '../../../protocols/interfaces';
Expand All @@ -7,6 +7,7 @@ import { ConsensusChannel } from '../../../channel/consensus-channel/consensus-c
import { VoucherInfo } from '../../../payments/vouchers';
import { SyncMap } from '../../../internal/safesync/safesync';
import { ObjectiveId } from '../../../protocols/messages';
import { Address } from '../../../types/types';

export class MemStore implements Store {
obectives: SyncMap<Buffer>;
Expand Down Expand Up @@ -41,8 +42,8 @@ export class MemStore implements Store {
close(): void {}

// TODO: Implement
getAddress(): AddressLike {
return ethers.ZeroAddress;
getAddress(): Address {
return ethers.constants.AddressZero;
}

// TODO: Implement
Expand Down Expand Up @@ -86,12 +87,12 @@ export class MemStore implements Store {
}

// TODO: Implement
getChannelsByAppDefinition(appDef: AddressLike): Channel[] {
getChannelsByAppDefinition(appDef: Address): Channel[] {
return [];
}

// TODO: Implement
getChannelsByParticipant(participant: AddressLike): Channel[] {
getChannelsByParticipant(participant: Address): Channel[] {
return [];
}

Expand All @@ -101,7 +102,7 @@ export class MemStore implements Store {
}

// TODO: Implement
getConsensusChannel(counterparty: AddressLike): ConsensusChannel {
getConsensusChannel(counterparty: Address): ConsensusChannel {
return {};
}

Expand Down
11 changes: 5 additions & 6 deletions packages/nitro-client/src/client/engine/store/store.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { AddressLike } from 'ethers';

import { Objective } from '../../../protocols/interfaces';
import { Channel } from '../../../channel/channel';
import { ConsensusChannel } from '../../../channel/consensus-channel/consensus-channel';
import { VoucherStore } from '../../../payments/voucher-manager';
import { Address } from '../../../types/types';

// Store is responsible for persisting objectives, objective metadata, states, signatures, private keys and blockchain data
export interface Store extends ConsensusChannelStore, VoucherStore {
// Get a pointer to a secret key for signing channel updates
getChannelSecretKey (): string

// Get the (Ethereum) address associated with the ChannelSecretKey
getAddress (): AddressLike
getAddress (): Address

// Read an existing objective
// TODO: Can throw an error
Expand All @@ -33,7 +32,7 @@ export interface Store extends ConsensusChannelStore, VoucherStore {
getChannelById (id: string): Channel

// Returns any channels that includes the given participant
getChannelsByParticipant (participant: AddressLike): Channel[]
getChannelsByParticipant (participant: Address): Channel[]

// TODO: Can throw an error
setChannel (ch: Channel): void
Expand All @@ -42,7 +41,7 @@ export interface Store extends ConsensusChannelStore, VoucherStore {

// Returns any channels that includes the given app definition
// TODO: Can throw an error
getChannelsByAppDefinition (appDef: AddressLike): Channel[]
getChannelsByAppDefinition (appDef: Address): Channel[]

// Release channel from being owned by any objective
releaseChannelFromOwnership (channelId: string): void
Expand All @@ -58,7 +57,7 @@ export interface ConsensusChannelStore {
getAllConsensusChannels (): ConsensusChannel[]

// TODO: Can throw an error
getConsensusChannel (counterparty: AddressLike): ConsensusChannel
getConsensusChannel (counterparty: Address): ConsensusChannel

// TODO: Can throw an error
getConsensusChannelById (id: string): ConsensusChannel
Expand Down
3 changes: 3 additions & 0 deletions packages/nitro-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export { Client } from './client/client';
export { EthChainService } from './client/engine/chainservice/eth-chainservice';

export const test = (): string => {
// eslint-disable-next-line no-console
console.log('Test from nitro-client');
Expand Down
8 changes: 3 additions & 5 deletions packages/nitro-client/src/payments/voucher-manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AddressLike } from 'ethers';

import { Voucher, VoucherInfo } from './vouchers';

// VoucherStore is an interface for storing voucher information that the voucher manager expects.
Expand All @@ -21,16 +19,16 @@ export interface VoucherStore {
export class VoucherManager {
private store: VoucherStore;

private me: AddressLike;
private me: string;

constructor(me: AddressLike, store: VoucherStore) {
constructor(me: string, store: VoucherStore) {
this.store = store;
this.me = me;
}

// Register registers a channel for use, given the payer, payee and starting balance of the channel
// TODO: Can throw an error
register(channelId: string, payer: AddressLike, payee: AddressLike, startingBalance: bigint): void {}
register(channelId: string, payer: string, payee: string, startingBalance: bigint): void {}

// Remove deletes the channel's status
// TODO: Can throw an error
Expand Down
6 changes: 2 additions & 4 deletions packages/nitro-client/src/payments/vouchers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AddressLike } from 'ethers';

// A Voucher signed by Alice can be used by Bob to redeem payments in case of
// a misbehaving Alice.
//
Expand All @@ -16,9 +14,9 @@ export class Voucher {}
// As well as details about the balance and who the payee/payer is.
// TODO: Implement
export class VoucherInfo {
channelPayer?: AddressLike;
channelPayer?: string;

channelPayee?: AddressLike;
channelPayee?: string;

startingBalance?: bigint;

Expand Down
5 changes: 2 additions & 3 deletions packages/nitro-client/src/protocols/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AddressLike } from 'ethers';

import { Message, ObjectiveId, ObjectivePayload } from './messages';
import { Proposal } from '../channel/consensus-channel/consensus-channel';
import { Address } from '../types/types';

// ChainTransaction defines the interface that every transaction must implement
export interface ChainTransaction {
Expand Down Expand Up @@ -74,7 +73,7 @@ export enum ObjectiveStatus {

// ObjectiveRequest is a request to create a new objective.
export interface ObjectiveRequest {
id (address: AddressLike, chainId: bigint): ObjectiveId
id (address: Address, chainId: bigint): ObjectiveId
waitForObjectiveToStart (): void
signalObjectiveStarted (): void
}
4 changes: 1 addition & 3 deletions packages/nitro-client/src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import { AddressLike } from 'ethers';

export type Address = AddressLike;
export type Address = string;
Loading

0 comments on commit 4ad0440

Please sign in to comment.