Skip to content

Commit

Permalink
feat: exposed setParserProvider configuration through TezosToolkit
Browse files Browse the repository at this point in the history
re #660
  • Loading branch information
hui-an-yang committed Oct 25, 2022
1 parent ad53532 commit 3280638
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/taquito/src/taquito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { LegacyWalletProvider, Wallet, WalletProvider } from './wallet';
import { OperationFactory } from './wallet/operation-factory';
import { TaquitoLocalForger } from './forger/taquito-local-forger';
import { EstimationProvider } from './estimate/estimate-provider-interface';
import { ParserProvider } from './parser/interface';
import { MichelCodecParser } from './parser/michel-codec-parser';

export { MichelsonMap, UnitValue } from '@taquito/michelson-encoder';
export { Forger, ForgeParams, ForgeResponse } from '@taquito/local-forging';
Expand Down Expand Up @@ -77,6 +79,7 @@ export interface SetProviderOptions {
config?: Partial<ConfigConfirmation>;
packer?: Packer;
globalConstantsProvider?: GlobalConstantsProvider;
parserProvider?: ParserProvider;
}

export interface VersionInfo {
Expand Down Expand Up @@ -135,6 +138,7 @@ export class TezosToolkit {
packer,
globalConstantsProvider,
readProvider,
parserProvider,
}: SetProviderOptions) {
this.setRpcProvider(rpc);
this.setStreamProvider(stream);
Expand All @@ -144,6 +148,7 @@ export class TezosToolkit {
this.setPackerProvider(packer);
this.setGlobalConstantsProvider(globalConstantsProvider);
this.setReadProvider(readProvider);
this.setParserProvider(parserProvider);

this._context.proto = protocol;
if (config) {
Expand Down Expand Up @@ -312,6 +317,27 @@ export class TezosToolkit {
this._context.readProvider = readP;
}

/**
* @description Sets parser provider on the Tezos Taquito instance
*
* @param options parserProvider to use to interact with the Tezos network
*
* @example
* ```
* Tezos.setParserProvider(new MichelCodecParser(...))
* ```
*/
setParserProvider(parserProvider?: SetProviderOptions['parserProvider']) {
if (!this._options.parserProvider && typeof parserProvider === 'undefined') {
const p = new MichelCodecParser(this._context);
this._context.parser = p;
this._options.parserProvider = p;
} else if (typeof parserProvider !== 'undefined') {
this._context.parser = parserProvider;
this._options.parserProvider = parserProvider;
}
}

/**
* @description Provide access to tezos account management
*/
Expand Down

0 comments on commit 3280638

Please sign in to comment.