-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from terra-money/feat/ibc/channels
feat: use IBC IdentifiedChannel
- Loading branch information
Showing
6 changed files
with
208 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,191 @@ | ||
import { | ||
State, | ||
Order, | ||
IdentifiedChannel as IdentifiedChannel_pb, | ||
} from '@terra-money/terra.proto/ibc/core/channel/v1/channel'; | ||
import { JSONSerializable } from '../../../../util/json'; | ||
import { Counterparty } from './Counterparty'; | ||
|
||
/** | ||
* IdentifiedChannel is a monotonically increasing data type | ||
* that can be compared against another IdentifiedChannel for the purposes of updating and | ||
* freezing clients | ||
* | ||
* Normally the RevisionChannel is incremented at each height while keeping | ||
* RevisionNumber the same. However some consensus algorithms may choose to | ||
* reset the height in certain conditions e.g. hard forks, state-machine | ||
* breaking changes In these cases, the RevisionNumber is incremented so that | ||
* height continues to be monitonically increasing even as the RevisionChannel | ||
* gets reset | ||
*/ | ||
export class IdentifiedChannel extends JSONSerializable< | ||
IdentifiedChannel.Amino, | ||
IdentifiedChannel.Data, | ||
IdentifiedChannel.Proto | ||
> { | ||
/** | ||
* @param state current state of the channel end | ||
* @param ordering whether the channel is ordered or unordered | ||
* @param counterparty counterparty channel end | ||
* @param connection_hops list of connection identifiers, in order, along which packets sent on this channel will travel | ||
* @param version opaque channel version, which is agreed upon during the handshake | ||
* @param port_id the | ||
* @param channel_id | ||
*/ | ||
constructor( | ||
public state: State, | ||
public ordering: Order, | ||
public counterparty: Counterparty | undefined, | ||
public connection_hops: string[], | ||
public version: string, | ||
public port_id: string, | ||
public channel_id: string | ||
) { | ||
super(); | ||
} | ||
|
||
public static fromAmino(data: IdentifiedChannel.Amino): IdentifiedChannel { | ||
const { | ||
state, | ||
ordering, | ||
counterparty, | ||
connection_hops, | ||
version, | ||
port_id, | ||
channel_id, | ||
} = data; | ||
return new IdentifiedChannel( | ||
state, | ||
ordering, | ||
counterparty ? Counterparty.fromAmino(counterparty) : undefined, | ||
connection_hops, | ||
version, | ||
port_id, | ||
channel_id | ||
); | ||
} | ||
|
||
public toAmino(): IdentifiedChannel.Amino { | ||
const { | ||
state, | ||
ordering, | ||
counterparty, | ||
connection_hops, | ||
version, | ||
port_id, | ||
channel_id, | ||
} = this; | ||
const res: IdentifiedChannel.Amino = { | ||
state, | ||
ordering, | ||
counterparty: counterparty ? counterparty.toAmino() : undefined, | ||
connection_hops, | ||
version, | ||
port_id, | ||
channel_id, | ||
}; | ||
return res; | ||
} | ||
|
||
public static fromData(data: IdentifiedChannel.Data): IdentifiedChannel { | ||
const { | ||
state, | ||
ordering, | ||
counterparty, | ||
connection_hops, | ||
version, | ||
port_id, | ||
channel_id, | ||
} = data; | ||
return new IdentifiedChannel( | ||
state, | ||
ordering, | ||
counterparty ? Counterparty.fromData(counterparty) : undefined, | ||
connection_hops, | ||
version, | ||
port_id, | ||
channel_id | ||
); | ||
} | ||
|
||
public toData(): IdentifiedChannel.Data { | ||
const { | ||
state, | ||
ordering, | ||
counterparty, | ||
connection_hops, | ||
version, | ||
port_id, | ||
channel_id, | ||
} = this; | ||
const res: IdentifiedChannel.Data = { | ||
state, | ||
ordering, | ||
counterparty: counterparty ? counterparty.toData() : undefined, | ||
connection_hops, | ||
version, | ||
port_id, | ||
channel_id, | ||
}; | ||
return res; | ||
} | ||
|
||
public static fromProto(proto: IdentifiedChannel.Proto): IdentifiedChannel { | ||
return new IdentifiedChannel( | ||
proto.state, | ||
proto.ordering, | ||
proto.counterparty | ||
? Counterparty.fromProto(proto.counterparty) | ||
: undefined, | ||
proto.connectionHops, | ||
proto.version, | ||
proto.portId, | ||
proto.channelId | ||
); | ||
} | ||
|
||
public toProto(): IdentifiedChannel.Proto { | ||
const { | ||
state, | ||
ordering, | ||
counterparty, | ||
connection_hops, | ||
version, | ||
port_id, | ||
channel_id, | ||
} = this; | ||
return IdentifiedChannel_pb.fromPartial({ | ||
state, | ||
ordering, | ||
counterparty: counterparty ? counterparty.toProto() : undefined, | ||
connectionHops: connection_hops, | ||
version, | ||
portId: port_id, | ||
channelId: channel_id, | ||
}); | ||
} | ||
} | ||
|
||
export namespace IdentifiedChannel { | ||
export interface Amino { | ||
state: State; | ||
ordering: Order; | ||
counterparty?: Counterparty.Amino; | ||
connection_hops: string[]; | ||
version: string; | ||
port_id: string; | ||
channel_id: string; | ||
} | ||
|
||
export interface Data { | ||
state: State; | ||
ordering: Order; | ||
counterparty?: Counterparty.Data; | ||
connection_hops: string[]; | ||
version: string; | ||
port_id: string; | ||
channel_id: string; | ||
} | ||
|
||
export type Proto = IdentifiedChannel_pb; | ||
} |
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,2 +1,5 @@ | ||
export * from './Channel'; | ||
export * from './Counterparty'; | ||
export * from './PacketId'; | ||
export * from './Packet'; | ||
export * from './IdentifiedChannel'; |
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,3 +1,2 @@ | ||
export * from './channel'; | ||
export * from './commitment'; | ||
export * from './connection'; |