Skip to content

Commit

Permalink
[TypeScript SDK] clean up headers gating (MystenLabs#8582)
Browse files Browse the repository at this point in the history
## Description 

Clean up gating code since 0.27.0 has been released.

## Test Plan 

1. CI test 
2. Verified that explorer is working properly
https://explorer-git-chris-cleanup-version-mysten-labs.vercel.app/
  • Loading branch information
666lcz authored Feb 23, 2023
1 parent 5719608 commit bf60d61
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
28 changes: 0 additions & 28 deletions sdk/typescript/src/providers/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ import {
CheckpointDigest,
CheckPointContentsDigest,
CommitteeInfo,
versionToString,
} from '../types';
import { lt } from '@suchipi/femver';
import { DynamicFieldName, DynamicFieldPage } from '../types/dynamic_fields';
import {
DEFAULT_CLIENT_OPTIONS,
Expand All @@ -71,7 +69,6 @@ import { UnserializedSignableTransaction } from '../signers/txn-data-serializers
import { LocalTxnDataSerializer } from '../signers/txn-data-serializers/local-txn-data-serializer';
import { toB64 } from '@mysten/bcs';
import { SerializedSignature } from '../cryptography/signature';
import { pkgVersion } from '../pkg-version';
import { Connection, devnetConnection } from '../rpc/connection';

export const TARGETED_RPC_VERSION = '0.27.0';
Expand Down Expand Up @@ -122,7 +119,6 @@ export class JsonRpcProvider extends Provider {
protected wsClient: WebsocketClient;
private rpcApiVersion: RpcApiVersion | undefined;
private cacheExpiry: number | undefined;
private addedHeaders = false;
/**
* Establish a connection to a Sui RPC endpoint
*
Expand All @@ -139,17 +135,6 @@ export class JsonRpcProvider extends Provider {
this.connection = connection;

const opts = { ...DEFAULT_OPTIONS, ...options };

// TODO: uncomment this when 0.27.0 is released. We cannot do this now because
// the current Devnet(0.26.0) does not support the header. And we need to make
// a request to RPC to know which version it is running. Therefore, we do not
// add headers here, instead we add headers in the first call of the `getRpcApiVersion`
// method
// this.client = new JsonRpcClient(this.endpoints.fullNode, {
// 'Client-Sdk-Type': 'typescript',
// 'Client-Sdk-Version': pkgVersion,
// 'Client-Target-Api-Version': TARGETED_RPC_VERSION,
// });
// TODO: add header for websocket request
this.client = opts.rpcClient ?? new JsonRpcClient(this.connection.fullnode);

Expand Down Expand Up @@ -178,19 +163,6 @@ export class JsonRpcProvider extends Provider {
this.options.skipDataValidation,
);
this.rpcApiVersion = parseVersionFromString(resp.info.version);
// TODO: Remove this once 0.27.0 is released
if (
!this.addedHeaders &&
this.rpcApiVersion &&
!lt(versionToString(this.rpcApiVersion), '0.27.0')
) {
this.client = new JsonRpcClient(this.connection.fullnode, {
'Client-Sdk-Type': 'typescript',
'Client-Sdk-Version': pkgVersion,
'Client-Target-Api-Version': TARGETED_RPC_VERSION,
});
this.addedHeaders = true;
}
this.cacheExpiry =
// Date.now() is in milliseconds, but the timeout is in seconds
Date.now() + (this.options.versionCacheTimeoutInSeconds ?? 0) * 1000;
Expand Down
13 changes: 5 additions & 8 deletions sdk/typescript/src/rpc/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
Struct,
validate,
} from 'superstruct';
import { pkgVersion } from '../pkg-version';
import { TARGETED_RPC_VERSION } from '../providers/json-rpc-provider';

/**
* An object defining headers to be passed to the RPC server
Expand Down Expand Up @@ -63,15 +65,10 @@ export class JsonRpcClient {
body: request,
headers: {
'Content-Type': 'application/json',
'Client-Sdk-Type': 'typescript',
'Client-Sdk-Version': pkgVersion,
'Client-Target-Api-Version': TARGETED_RPC_VERSION,
...httpHeaders,
// TODO: uncomment this when 0.27.0 is released. We cannot do this now because
// the current Devnet(0.26.0) does not support the header. And we need to make
// a request to RPC to know which version it is running. Therefore, we do not
// add headers here, instead we add headers in the first call of the `getRpcApiVersion`
// method
// 'Client-Sdk-Type': 'typescript',
// 'Client-Sdk-Version': pkgVersion,
// 'Client-Target-Api-Version': TARGETED_RPC_VERSION,
},
};

Expand Down

0 comments on commit bf60d61

Please sign in to comment.