-
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 engine with placeholder types and interfaces (#3)
* Add empty types for engine and client * Add engine components with empty types * Fix lint errors * Add typed placeholders to channel fields in Engine class * Add methods to ChainService interface * Add methods to MessageService interface * Update test method import
- Loading branch information
1 parent
4c4f820
commit f120c7f
Showing
17 changed files
with
165 additions
and
5 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
5 changes: 5 additions & 0 deletions
5
packages/nitro-client/src/channel/consensus_channel/consensus_channel.ts
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Proposal is a proposal either to add or to remove a guarantee. | ||
// | ||
// Exactly one of {toAdd, toRemove} should be non nil. | ||
// TODO Implement | ||
export class Proposal {} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# Client |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { MessageService } from './engine/messageservice/messageservice'; | ||
import { ChainService } from './engine/chainservice/chainservice'; | ||
import { Store } from './engine/store/store'; | ||
import { PolicyMaker } from './engine/policy-maker'; | ||
import { VoucherManager } from '../payments/voucher-manager'; | ||
import { Engine } from './engine/engine'; | ||
|
||
export class Client { | ||
// The core business logic of the client | ||
private engine: Engine; | ||
|
||
private vm: VoucherManager; | ||
|
||
constructor(msg: MessageService, chain: ChainService, store: Store, policymaker: PolicyMaker) { | ||
this.vm = new VoucherManager(); | ||
this.engine = new Engine(this.vm, msg, chain, store, policymaker); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/nitro-client/src/client/engine/chainservice/chainservice.ts
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { GoReceivingChannelPlaceholder } from '../../../go-channel'; | ||
import { ChainTransaction } from '../../../protocols/interfaces'; | ||
|
||
// Event dictates which methods all chain events must implement | ||
// TODO: Add methods | ||
export interface Event {} | ||
|
||
// TODO: Add eth chainservice implementation | ||
export interface ChainService { | ||
eventFeed (): GoReceivingChannelPlaceholder<Event>; | ||
|
||
// TODO: Use protocols chain transaction type | ||
// TODO: Can throw an error | ||
sendTransaction (tx: ChainTransaction): void; | ||
|
||
// TODO: Use Address type | ||
getConsensusAppAddress (): string; | ||
|
||
getVirtualPaymentAppAddress (): string; | ||
|
||
// TODO: Can throw an error | ||
getChainId (): number; | ||
|
||
// TODO: Can throw an error | ||
close (): void; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { GoChannelPlaceholder, GoReceivingChannelPlaceholder } from '../../go-channel'; | ||
import { MessageService } from './messageservice/messageservice'; | ||
import { ChainService, Event as ChainEvent } from './chainservice/chainservice'; | ||
import { Store } from './store/store'; | ||
import { PolicyMaker } from './policy-maker'; | ||
import { MetricsRecorder } from './metrics'; | ||
import { VoucherManager } from '../../payments/voucher-manager'; | ||
import { ObjectiveRequest } from '../../protocols/interfaces'; | ||
import { Message } from '../../protocols/messages'; | ||
import { Proposal } from '../../channel/consensus_channel/consensus_channel'; | ||
|
||
export class Engine { | ||
objectiveRequestsFromAPI?: GoChannelPlaceholder<ObjectiveRequest>; | ||
|
||
paymentRequestsFromAPI?: GoChannelPlaceholder<PaymentRequest>; | ||
|
||
private fromChain?: GoReceivingChannelPlaceholder<ChainEvent>; | ||
|
||
private fromMsg?: GoReceivingChannelPlaceholder<Message>; | ||
|
||
private fromLedger?: GoChannelPlaceholder<Proposal>; | ||
|
||
private toApi?: GoChannelPlaceholder<EngineEvent>; | ||
|
||
private stop?: GoChannelPlaceholder<void>; | ||
|
||
private msg: MessageService; | ||
|
||
private chain: ChainService; | ||
|
||
// A Store for persisting and restoring important data | ||
private store: Store; | ||
|
||
// A PolicyMaker decides whether to approve or reject objectives | ||
private policymaker: PolicyMaker; | ||
|
||
// logger zerolog.Logger | ||
|
||
private metrics?: MetricsRecorder; | ||
|
||
private vm: VoucherManager; | ||
|
||
constructor( | ||
vm: VoucherManager, | ||
msg: MessageService, | ||
chain: ChainService, | ||
store: Store, | ||
policymaker: PolicyMaker, | ||
) { | ||
this.vm = vm; | ||
|
||
this.msg = msg; | ||
this.chain = chain; | ||
this.store = store; | ||
|
||
this.policymaker = policymaker; | ||
} | ||
} | ||
|
||
export type PaymentRequest = { | ||
channelId: string | ||
amount: number | ||
}; | ||
|
||
// TODO Implement | ||
export class EngineEvent {} |
19 changes: 19 additions & 0 deletions
19
packages/nitro-client/src/client/engine/messageservice/messageservice.ts
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { GoReceivingChannelPlaceholder } from '../../../go-channel'; | ||
import { Message } from '../../../protocols/messages'; | ||
|
||
// TODO: Add p2p implementation | ||
// TODO: Add tests | ||
export interface MessageService { | ||
// TODO: Update comments | ||
|
||
// Out returns a chan for receiving messages from the message service | ||
out (): GoReceivingChannelPlaceholder<Message>; | ||
|
||
// Send is for sending messages with the message service | ||
// TODO: Use protocols message type | ||
send (msg: Message): void; | ||
|
||
// Close closes the message service | ||
// TODO: Can throw an error | ||
close (): void; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// TODO: Implement | ||
export class MetricsRecorder {} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// TODO: Add methods | ||
export interface PolicyMaker {} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// TODO: Add methods | ||
export interface Store {} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* eslint max-classes-per-file: 0 */ | ||
/* eslint @typescript-eslint/no-unused-vars: 0 */ | ||
|
||
// TODO: Replace | ||
export class GoChannelPlaceholder<T> {} | ||
export class GoReceivingChannelPlaceholder<T> {} |
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,8 +1,8 @@ | ||
const test = (): string => { | ||
export const test = (): string => { | ||
// eslint-disable-next-line no-console | ||
console.log('Test from nitro-client'); | ||
|
||
return 'test output'; | ||
}; | ||
|
||
export default test; | ||
export { Client } from './client/client'; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// TODO: Implement | ||
export class VoucherManager {} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// ChainTransaction defines the interface that every transaction must implement | ||
// TODO: Add methods | ||
export interface ChainTransaction {} | ||
|
||
// ObjectiveRequest is a request to create a new objective. | ||
// TODO: Add methods | ||
export interface ObjectiveRequest {} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// TODO Implement | ||
export class Message {} |
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