-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ClientUpdateProposal type.
- Loading branch information
Showing
4 changed files
with
170 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ClientUpdateProposal } from './ClientUpdateProposal'; | ||
|
||
describe('ClientUpdateProposal', () => { | ||
const update: ClientUpdateProposal.Data = { | ||
'@type': '/ibc.core.client.v1.ClientUpdateProposal', | ||
title: 'Update expired ibc client', | ||
description: 'Proposal to update an IBC client which has expired.', | ||
subject_client_id: '07-tendermint-19', | ||
substitute_client_id: '07-tendermint-64', | ||
}; | ||
|
||
it('parses IBC client upgrade proposal', () => { | ||
expect(ClientUpdateProposal.fromData(update)).toBeTruthy(); | ||
}); | ||
}); |
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,139 @@ | ||
import { JSONSerializable } from '../../../util/json'; | ||
import { Any } from '@terra-money/terra.proto/google/protobuf/any'; | ||
import { ClientUpdateProposal as ClientUpdateProposal_pb } from '@terra-money/terra.proto/ibc/core/client/v1/client'; | ||
|
||
/** | ||
* Proposal that allows updating IBC clients. If it passes, the substitute | ||
* client's latest consensus state is copied over to the subject client. | ||
*/ | ||
export class ClientUpdateProposal extends JSONSerializable< | ||
ClientUpdateProposal.Amino, | ||
ClientUpdateProposal.Data, | ||
ClientUpdateProposal.Proto | ||
> { | ||
public subjectClientId: string; | ||
public substituteClientId: string; | ||
/** | ||
* @param title proposal's title | ||
* @param description proposal's description | ||
* @param subjectClientId client to update | ||
* @param substituteClientId client to copy | ||
*/ | ||
constructor( | ||
public title: string, | ||
public description: string, | ||
subjectClientId: string, | ||
substituteClientId: string | ||
) { | ||
super(); | ||
this.subjectClientId = subjectClientId; | ||
this.substituteClientId = substituteClientId; | ||
} | ||
|
||
public static fromAmino( | ||
data: ClientUpdateProposal.Amino | ||
): ClientUpdateProposal { | ||
const { | ||
value: { title, description, subjectClientId, substituteClientId }, | ||
} = data; | ||
return new ClientUpdateProposal( | ||
title, | ||
description, | ||
subjectClientId, | ||
substituteClientId | ||
); | ||
} | ||
|
||
public toAmino(): ClientUpdateProposal.Amino { | ||
const { title, description, subjectClientId, substituteClientId } = this; | ||
return { | ||
type: 'ibc/ClientUpdateProposal', | ||
value: { | ||
title, | ||
description, | ||
subjectClientId, | ||
substituteClientId, | ||
}, | ||
}; | ||
} | ||
|
||
public static fromData( | ||
data: ClientUpdateProposal.Data | ||
): ClientUpdateProposal { | ||
const { title, description, subject_client_id, substitute_client_id } = | ||
data; | ||
return new ClientUpdateProposal( | ||
title, | ||
description, | ||
subject_client_id, | ||
substitute_client_id | ||
); | ||
} | ||
|
||
public toData(): ClientUpdateProposal.Data { | ||
const { title, description, subjectClientId, substituteClientId } = this; | ||
return { | ||
'@type': '/ibc.core.client.v1.ClientUpdateProposal', | ||
title, | ||
description, | ||
subject_client_id: subjectClientId, | ||
substitute_client_id: substituteClientId, | ||
}; | ||
} | ||
|
||
public static fromProto( | ||
proto: ClientUpdateProposal.Proto | ||
): ClientUpdateProposal { | ||
return new ClientUpdateProposal( | ||
proto.title, | ||
proto.description, | ||
proto.subjectClientId, | ||
proto.substituteClientId | ||
); | ||
} | ||
|
||
public toProto(): ClientUpdateProposal.Proto { | ||
const { title, description, subjectClientId, substituteClientId } = this; | ||
return ClientUpdateProposal_pb.fromPartial({ | ||
subjectClientId, | ||
substituteClientId, | ||
description, | ||
title, | ||
}); | ||
} | ||
|
||
public packAny(): Any { | ||
return Any.fromPartial({ | ||
typeUrl: '/ibc.core.client.v1.ClientUpdateProposal', | ||
value: ClientUpdateProposal_pb.encode(this.toProto()).finish(), | ||
}); | ||
} | ||
|
||
public static unpackAny(msgAny: Any): ClientUpdateProposal { | ||
return ClientUpdateProposal.fromProto( | ||
ClientUpdateProposal_pb.decode(msgAny.value) | ||
); | ||
} | ||
} | ||
|
||
export namespace ClientUpdateProposal { | ||
export interface Amino { | ||
type: 'ibc/ClientUpdateProposal'; | ||
value: { | ||
title: string; | ||
description: string; | ||
subjectClientId: string; | ||
substituteClientId: string; | ||
}; | ||
} | ||
|
||
export interface Data { | ||
'@type': '/ibc.core.client.v1.ClientUpdateProposal'; | ||
title: string; | ||
description: string; | ||
subject_client_id: string; | ||
substitute_client_id: string; | ||
} | ||
|
||
export type Proto = ClientUpdateProposal_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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ClientUpdateProposal'; |