Skip to content

Commit

Permalink
feat: support new operation drainDelegate for Lima
Browse files Browse the repository at this point in the history
  • Loading branch information
hui-an-yang committed Nov 8, 2022
1 parent e0126e5 commit 984e3a5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/taquito-local-forging/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export enum CODEC {
TX_ROLLUP_BATCH_CONTENT = 'tx_rollup_batch_content',
OP_INCREASE_PAID_STORAGE = 'increase_paid_storage',
OP_UPDATE_CONSENSUS_KEY = 'update_consensus_key',
OP_DRAIN_DELEGATE = 'drain_delegate',
}

// See https://tezos.gitlab.io/whitedoc/michelson.html#full-grammar
Expand Down Expand Up @@ -233,6 +234,7 @@ export const kindMapping: { [key: number]: string } = {
0x9e: 'transfer_ticket',
0x71: 'increase_paid_storage',
0x72: 'update_consensus_key',
0x09: 'drain_delegate',
};

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 @@ -30,6 +30,7 @@ import {
EndorsementSchema,
IncreasePaidStorageSchema,
UpdateConsensusKeySchema,
DrainDelegateSchema,
ManagerOperationSchema,
operationDecoder,
OriginationSchema,
Expand Down Expand Up @@ -104,4 +105,6 @@ 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.OP_DRAIN_DELEGATE] = (val: Uint8ArrayConsumer) =>
schemaDecoder(decoders)(DrainDelegateSchema)(val);
decoders[CODEC.MANAGER] = schemaDecoder(decoders)(ManagerOperationSchema);
2 changes: 2 additions & 0 deletions packages/taquito-local-forging/src/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
EndorsementSchema,
IncreasePaidStorageSchema,
UpdateConsensusKeySchema,
DrainDelegateSchema,
ManagerOperationSchema,
operationEncoder,
OriginationSchema,
Expand Down Expand Up @@ -96,4 +97,5 @@ 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.OP_DRAIN_DELEGATE] = (val: any) => schemaEncoder(encoders)(DrainDelegateSchema)(val);
encoders[CODEC.MANAGER] = schemaEncoder(encoders)(ManagerOperationSchema);
6 changes: 6 additions & 0 deletions packages/taquito-local-forging/src/schema/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ export const UpdateConsensusKeySchema = {
pk: CODEC.PUBLIC_KEY,
};

export const DrainDelegateSchema = {
consensus_key: CODEC.PKH,
delegate: CODEC.PKH,
destination: CODEC.PKH,
};

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 @@ -16,6 +16,7 @@ import {
TxRollupSubmitBatchSchema,
IncreasePaidStorageSchema,
UpdateConsensusKeySchema,
DrainDelegateSchema,
} from './schema/operation';

type OperationKind =
Expand All @@ -33,7 +34,8 @@ type OperationKind =
| OpKind.TX_ROLLUP_ORIGINATION
| OpKind.TX_ROLLUP_SUBMIT_BATCH
| OpKind.INCREASE_PAID_STORAGE
| OpKind.UPDATE_CONSENSUS_KEY;
| OpKind.UPDATE_CONSENSUS_KEY
| OpKind.DRAIN_DELEGATE;

const OperationKindMapping = {
activate_account: ActivationSchema,
Expand All @@ -51,6 +53,7 @@ const OperationKindMapping = {
tx_rollup_submit_batch: TxRollupSubmitBatchSchema,
increase_paid_storage: IncreasePaidStorageSchema,
update_consensus_key: UpdateConsensusKeySchema,
drain_delegate: DrainDelegateSchema,
};

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

0 comments on commit 984e3a5

Please sign in to comment.