Skip to content

Commit

Permalink
feat: support new operation updateConsensusKey in local-forger for Lima
Browse files Browse the repository at this point in the history
  • Loading branch information
hui-an-yang committed Nov 7, 2022
1 parent 029efa1 commit 2992fcf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/taquito-local-forging/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export enum CODEC {
TX_ROLLUP_ID = 'tx_rollup_id',
TX_ROLLUP_BATCH_CONTENT = 'tx_rollup_batch_content',
OP_INCREASE_PAID_STORAGE = 'increase_paid_storage',
OP_UPDATE_CONSENSUS_KEY = 'update_consensus_key',
}

// See https://tezos.gitlab.io/whitedoc/michelson.html#full-grammar
Expand Down Expand Up @@ -215,7 +216,7 @@ export const opMappingReverse = (() => {
return result;
})();

// See https://tezos.gitlab.io/api/p2p.html
// See https://tezos.gitlab.io/shell/p2p_api.html?highlight=p2p
export const kindMapping: { [key: number]: string } = {
0x04: 'activate_account',
0x6b: 'reveal',
Expand All @@ -231,6 +232,7 @@ export const kindMapping: { [key: number]: string } = {
0x97: 'tx_rollup_submit_batch',
0x9e: 'transfer_ticket',
0x71: 'increase_paid_storage',
0x72: 'update_consensus_key',
};

export const kindMappingReverse = (() => {
Expand Down
3 changes: 3 additions & 0 deletions packages/taquito-local-forging/src/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DelegationSchema,
EndorsementSchema,
IncreasePaidStorageSchema,
UpdateConsensusKeySchema,
ManagerOperationSchema,
operationDecoder,
OriginationSchema,
Expand Down Expand Up @@ -101,4 +102,6 @@ decoders[CODEC.OP_TX_ROLLUP_SUBMIT_BATCH] = (val: Uint8ArrayConsumer) =>
schemaDecoder(decoders)(TxRollupSubmitBatchSchema)(val);
decoders[CODEC.OP_INCREASE_PAID_STORAGE] = (val: Uint8ArrayConsumer) =>
schemaDecoder(decoders)(IncreasePaidStorageSchema)(val);
decoders[CODEC.OP_UPDATE_CONSENSUS_KEY] = (val: Uint8ArrayConsumer) =>
schemaDecoder(decoders)(UpdateConsensusKeySchema)(val);
decoders[CODEC.MANAGER] = schemaDecoder(decoders)(ManagerOperationSchema);
3 changes: 3 additions & 0 deletions packages/taquito-local-forging/src/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DelegationSchema,
EndorsementSchema,
IncreasePaidStorageSchema,
UpdateConsensusKeySchema,
ManagerOperationSchema,
operationEncoder,
OriginationSchema,
Expand Down Expand Up @@ -93,4 +94,6 @@ encoders[CODEC.OP_TX_ROLLUP_SUBMIT_BATCH] = (val: any) =>
schemaEncoder(encoders)(TxRollupSubmitBatchSchema)(val);
encoders[CODEC.OP_INCREASE_PAID_STORAGE] = (val: any) =>
schemaEncoder(encoders)(IncreasePaidStorageSchema)(val);
encoders[CODEC.OP_UPDATE_CONSENSUS_KEY] = (val: any) =>
schemaEncoder(encoders)(UpdateConsensusKeySchema)(val);
encoders[CODEC.MANAGER] = schemaEncoder(encoders)(ManagerOperationSchema);
9 changes: 9 additions & 0 deletions packages/taquito-local-forging/src/schema/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ export const IncreasePaidStorageSchema = {
destination: CODEC.SMART_CONTRACT_ADDRESS,
};

export const UpdateConsensusKeySchema = {
source: CODEC.PKH,
fee: CODEC.ZARITH,
counter: CODEC.ZARITH,
gas_limit: CODEC.ZARITH,
storage_limit: CODEC.ZARITH,
pk: CODEC.PUBLIC_KEY,
};

export const operationEncoder =
(encoders: { [key: string]: (val: object) => string }) => (operation: { kind: string }) => {
if (!(operation.kind in encoders) || !(operation.kind in kindMappingReverse)) {
Expand Down
5 changes: 4 additions & 1 deletion packages/taquito-local-forging/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
TxRollupOriginationSchema,
TxRollupSubmitBatchSchema,
IncreasePaidStorageSchema,
UpdateConsensusKeySchema,
} from './schema/operation';

type OperationKind =
Expand All @@ -31,7 +32,8 @@ type OperationKind =
| OpKind.TRANSFER_TICKET
| OpKind.TX_ROLLUP_ORIGINATION
| OpKind.TX_ROLLUP_SUBMIT_BATCH
| OpKind.INCREASE_PAID_STORAGE;
| OpKind.INCREASE_PAID_STORAGE
| OpKind.UPDATE_CONSENSUS_KEY;

const OperationKindMapping = {
activate_account: ActivationSchema,
Expand All @@ -48,6 +50,7 @@ const OperationKindMapping = {
tx_rollup_origination: TxRollupOriginationSchema,
tx_rollup_submit_batch: TxRollupSubmitBatchSchema,
increase_paid_storage: IncreasePaidStorageSchema,
update_consensus_key: UpdateConsensusKeySchema,
};

// Asymmetric difference: only account for things in arr2 that are not present in arr1, not vice versa
Expand Down

0 comments on commit 2992fcf

Please sign in to comment.