Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

feat: add driveProtocolVersion option #249

Merged
merged 17 commits into from
Aug 24, 2021
40 changes: 32 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@dashevo/dapi-client": "~0.21.0-dev.3",
"@dashevo/dashcore-lib": "~0.19.25",
"@dashevo/dpp": "~0.20.0",
"@dashevo/dpp": "~0.21.0-dev.1",
"@dashevo/wallet-lib": "~7.21.0-dev.2",
"bs58": "^4.0.1",
"node-inspect-extracted": "1.0.7"
Expand Down
18 changes: 18 additions & 0 deletions src/SDK/Client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DAPIClientTransport from "@dashevo/wallet-lib/src/transport/DAPIClientTra
import { Platform } from './Platform';
import { Network } from "@dashevo/dashcore-lib";
import DAPIClient from "@dashevo/dapi-client";
import { latestVersion as latestProtocolVersion } from "@dashevo/dpp/lib/protocolVersion";
import { ClientApps, ClientAppsOptions } from "./ClientApps";

export interface WalletOptions extends Wallet.IWalletOptions {
Expand Down Expand Up @@ -33,6 +34,7 @@ export interface ClientOpts {
timeout?: number,
retries?: number,
baseBanTime?: number,
driveProtocolVersion?: number,
}

/**
Expand All @@ -45,9 +47,14 @@ export class Client extends EventEmitter {
public account: Account | undefined;
public platform: Platform;
public defaultAccountIndex: number | undefined = 0;
public driveProtocolVersion: number;
private readonly dapiClient: DAPIClient;
private readonly apps: ClientApps;
private options: ClientOpts;
private static readonly networkToProtocolVersion: Map<string, number> = new Map([
['testnet', 0],
['regtest', 0],
]);

/**
* Construct some instance of SDK Client
Expand All @@ -61,6 +68,17 @@ export class Client extends EventEmitter {

this.network = this.options.network ? this.options.network.toString() : 'testnet';

const mappedProtocolVersion = Client.networkToProtocolVersion.get(
this.network,
);

// use protocol version from options if set
// use mapped one otherwise
// fallback to one that set in dpp as the last option
this.driveProtocolVersion = this.options.driveProtocolVersion !== undefined
? this.options.driveProtocolVersion
: (mappedProtocolVersion !== undefined ? mappedProtocolVersion : latestProtocolVersion);
shumkov marked this conversation as resolved.
Show resolved Hide resolved

// Initialize DAPI Client
const dapiClientOptions = {
network: this.network,
Expand Down
1 change: 1 addition & 0 deletions src/SDK/Client/Platform/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class Platform {

this.dpp = new DashPlatformProtocol({
stateRepository,
protocolVersion: this.client.driveProtocolVersion,
...options,
});
}
Expand Down