fix: remove legacy code
This commit is contained in:
committed by
Michael Vines
parent
aea0e83a40
commit
4a547b0057
@ -30,17 +30,12 @@ type RpcResponseAndContext<T> = {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function jsonRpcResultAndContext(resultDescription: any) {
|
function jsonRpcResultAndContext(resultDescription: any) {
|
||||||
return struct.union([
|
return jsonRpcResult({
|
||||||
// those same methods return results with context in v0.21+ servers
|
|
||||||
jsonRpcResult({
|
|
||||||
context: struct({
|
context: struct({
|
||||||
slot: 'number',
|
slot: 'number',
|
||||||
}),
|
}),
|
||||||
value: resultDescription,
|
value: resultDescription,
|
||||||
}),
|
});
|
||||||
// selected methods return "bare" results in pre-v0.21 servers
|
|
||||||
jsonRpcResult(resultDescription),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -375,19 +370,6 @@ const GetClusterNodes = jsonRpcResult(
|
|||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
const GetClusterNodes_015 = jsonRpcResult(
|
|
||||||
struct.list([
|
|
||||||
struct({
|
|
||||||
id: 'string',
|
|
||||||
gossip: 'string',
|
|
||||||
tpu: struct.union(['null', 'string']),
|
|
||||||
rpc: struct.union(['null', 'string']),
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expected JSON RPC response for the "getVoteAccounts" message
|
* Expected JSON RPC response for the "getVoteAccounts" message
|
||||||
@ -515,20 +497,6 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext([
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
const GetRecentBlockhash_016 = jsonRpcResult([
|
|
||||||
'string',
|
|
||||||
struct({
|
|
||||||
lamportsPerSignature: 'number',
|
|
||||||
maxLamportsPerSignature: 'number',
|
|
||||||
minLamportsPerSignature: 'number',
|
|
||||||
targetLamportsPerSignature: 'number',
|
|
||||||
targetSignaturesPerSlot: 'number',
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expected JSON RPC response for the "requestAirdrop" message
|
* Expected JSON RPC response for the "requestAirdrop" message
|
||||||
*/
|
*/
|
||||||
@ -722,21 +690,7 @@ export class Connection {
|
|||||||
throw new Error(res.error.message);
|
throw new Error(res.error.message);
|
||||||
}
|
}
|
||||||
assert(typeof res.result !== 'undefined');
|
assert(typeof res.result !== 'undefined');
|
||||||
|
|
||||||
const isV021 =
|
|
||||||
typeof res.result.context !== 'undefined' &&
|
|
||||||
typeof res.result.value !== 'undefined';
|
|
||||||
|
|
||||||
if (isV021) {
|
|
||||||
return res.result;
|
return res.result;
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
context: {
|
|
||||||
slot: NaN,
|
|
||||||
},
|
|
||||||
value: res.result,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
async getBalance(
|
async getBalance(
|
||||||
publicKey: PublicKey,
|
publicKey: PublicKey,
|
||||||
@ -764,18 +718,11 @@ export class Connection {
|
|||||||
}
|
}
|
||||||
assert(typeof res.result !== 'undefined');
|
assert(typeof res.result !== 'undefined');
|
||||||
|
|
||||||
const isV021 =
|
if (!res.result.value) {
|
||||||
typeof res.result.context !== 'undefined' &&
|
|
||||||
typeof res.result.value !== 'undefined';
|
|
||||||
|
|
||||||
const slot = isV021 ? res.result.context.slot : NaN;
|
|
||||||
const resultValue = isV021 ? res.result.value : res.result;
|
|
||||||
|
|
||||||
if (!resultValue) {
|
|
||||||
throw new Error('Invalid request');
|
throw new Error('Invalid request');
|
||||||
}
|
}
|
||||||
|
|
||||||
const {executable, owner, lamports, data} = resultValue;
|
const {executable, owner, lamports, data} = res.result.value;
|
||||||
const value = {
|
const value = {
|
||||||
executable,
|
executable,
|
||||||
owner: new PublicKey(owner),
|
owner: new PublicKey(owner),
|
||||||
@ -785,7 +732,7 @@ export class Connection {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
context: {
|
context: {
|
||||||
slot,
|
slot: res.result.context.slot,
|
||||||
},
|
},
|
||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
@ -845,21 +792,7 @@ export class Connection {
|
|||||||
throw new Error(res.error.message);
|
throw new Error(res.error.message);
|
||||||
}
|
}
|
||||||
assert(typeof res.result !== 'undefined');
|
assert(typeof res.result !== 'undefined');
|
||||||
|
|
||||||
const isV021 =
|
|
||||||
typeof res.result.context !== 'undefined' &&
|
|
||||||
typeof res.result.value !== 'undefined';
|
|
||||||
|
|
||||||
if (isV021) {
|
|
||||||
return res.result;
|
return res.result;
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
context: {
|
|
||||||
slot: NaN,
|
|
||||||
},
|
|
||||||
value: res.result,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
async confirmTransaction(
|
async confirmTransaction(
|
||||||
signature: TransactionSignature,
|
signature: TransactionSignature,
|
||||||
@ -878,23 +811,6 @@ export class Connection {
|
|||||||
async getClusterNodes(): Promise<Array<ContactInfo>> {
|
async getClusterNodes(): Promise<Array<ContactInfo>> {
|
||||||
const unsafeRes = await this._rpcRequest('getClusterNodes', []);
|
const unsafeRes = await this._rpcRequest('getClusterNodes', []);
|
||||||
|
|
||||||
// Legacy v0.15 response. TODO: Remove in August 2019
|
|
||||||
try {
|
|
||||||
const res_015 = GetClusterNodes_015(unsafeRes);
|
|
||||||
if (res_015.error) {
|
|
||||||
console.log('no', res_015.error);
|
|
||||||
throw new Error(res_015.error.message);
|
|
||||||
}
|
|
||||||
return res_015.result.map(node => {
|
|
||||||
node.pubkey = node.id;
|
|
||||||
node.id = undefined;
|
|
||||||
return node;
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
// Not legacy format
|
|
||||||
}
|
|
||||||
// End Legacy v0.15 response
|
|
||||||
|
|
||||||
const res = GetClusterNodes(unsafeRes);
|
const res = GetClusterNodes(unsafeRes);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
throw new Error(res.error.message);
|
throw new Error(res.error.message);
|
||||||
@ -1063,46 +979,12 @@ export class Connection {
|
|||||||
const args = this._argsWithCommitment([], commitment);
|
const args = this._argsWithCommitment([], commitment);
|
||||||
const unsafeRes = await this._rpcRequest('getRecentBlockhash', args);
|
const unsafeRes = await this._rpcRequest('getRecentBlockhash', args);
|
||||||
|
|
||||||
// Legacy v0.16 response. TODO: Remove in September 2019
|
|
||||||
try {
|
|
||||||
const res_016 = GetRecentBlockhash_016(unsafeRes);
|
|
||||||
if (res_016.error) {
|
|
||||||
throw new Error(res_016.error.message);
|
|
||||||
}
|
|
||||||
const [blockhash, feeCalculator] = res_016.result;
|
|
||||||
feeCalculator.burnPercent = 0;
|
|
||||||
|
|
||||||
return {
|
|
||||||
context: {
|
|
||||||
slot: NaN,
|
|
||||||
},
|
|
||||||
value: [blockhash, feeCalculator],
|
|
||||||
};
|
|
||||||
} catch (e) {
|
|
||||||
// Not legacy format
|
|
||||||
}
|
|
||||||
// End Legacy v0.16 response
|
|
||||||
|
|
||||||
const res = GetRecentBlockhashAndContextRpcResult(unsafeRes);
|
const res = GetRecentBlockhashAndContextRpcResult(unsafeRes);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
throw new Error(res.error.message);
|
throw new Error(res.error.message);
|
||||||
}
|
}
|
||||||
assert(typeof res.result !== 'undefined');
|
assert(typeof res.result !== 'undefined');
|
||||||
|
|
||||||
const isV021 =
|
|
||||||
typeof res.result.context !== 'undefined' &&
|
|
||||||
typeof res.result.value !== 'undefined';
|
|
||||||
|
|
||||||
if (isV021) {
|
|
||||||
return res.result;
|
return res.result;
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
context: {
|
|
||||||
slot: NaN,
|
|
||||||
},
|
|
||||||
value: res.result,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
async getRecentBlockhash(
|
async getRecentBlockhash(
|
||||||
commitment: ?Commitment,
|
commitment: ?Commitment,
|
||||||
@ -1167,23 +1049,17 @@ export class Connection {
|
|||||||
throw new Error(res.error.message);
|
throw new Error(res.error.message);
|
||||||
}
|
}
|
||||||
assert(typeof res.result !== 'undefined');
|
assert(typeof res.result !== 'undefined');
|
||||||
|
if (!res.result.value) {
|
||||||
const isV021 =
|
|
||||||
typeof res.result.context !== 'undefined' &&
|
|
||||||
typeof res.result.value !== 'undefined';
|
|
||||||
|
|
||||||
const slot = isV021 ? res.result.context.slot : NaN;
|
|
||||||
const resultValue = isV021 ? res.result.value : res.result;
|
|
||||||
|
|
||||||
if (!resultValue) {
|
|
||||||
throw new Error('Invalid request');
|
throw new Error('Invalid request');
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = NonceAccount.fromAccountData(Buffer.from(resultValue.data));
|
const value = NonceAccount.fromAccountData(
|
||||||
|
Buffer.from(res.result.value.data),
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
context: {
|
context: {
|
||||||
slot,
|
slot: res.result.context.slot,
|
||||||
},
|
},
|
||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
|
@ -217,7 +217,8 @@ export class Transaction {
|
|||||||
|
|
||||||
allKeys.sort(function(x, y) {
|
allKeys.sort(function(x, y) {
|
||||||
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
||||||
const checkWritable = x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
|
const checkWritable =
|
||||||
|
x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
|
||||||
return checkSigner || checkWritable;
|
return checkSigner || checkWritable;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -123,7 +123,12 @@ test('get balance', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: 0,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -518,7 +523,12 @@ test('request airdrop', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: 42,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: 42,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -537,6 +547,10 @@ test('request airdrop', async () => {
|
|||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: {
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: {
|
||||||
owner: [
|
owner: [
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -576,6 +590,7 @@ test('request airdrop', async () => {
|
|||||||
executable: false,
|
executable: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const accountInfo = await connection.getAccountInfo(account.publicKey);
|
const accountInfo = await connection.getAccountInfo(account.publicKey);
|
||||||
@ -609,7 +624,12 @@ test('request airdrop - max commitment', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: 40,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: 40,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -647,7 +667,12 @@ test('transaction', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: 100010,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: 100010,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
await connection.requestAirdrop(accountFrom.publicKey, 100010);
|
await connection.requestAirdrop(accountFrom.publicKey, 100010);
|
||||||
@ -673,7 +698,12 @@ test('transaction', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: 21,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: 21,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
await connection.requestAirdrop(accountTo.publicKey, 21);
|
await connection.requestAirdrop(accountTo.publicKey, 21);
|
||||||
@ -710,7 +740,12 @@ test('transaction', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: true,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -751,7 +786,12 @@ test('transaction', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: 2,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -768,7 +808,12 @@ test('transaction', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: 31,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: 31,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
expect(await connection.getBalance(accountTo.publicKey)).toBe(31);
|
expect(await connection.getBalance(accountTo.publicKey)).toBe(31);
|
||||||
|
@ -20,7 +20,11 @@ export function mockGetRecentBlockhash(commitment: ?Commitment) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: [
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: [
|
||||||
recentBlockhash.publicKey.toBase58(),
|
recentBlockhash.publicKey.toBase58(),
|
||||||
{
|
{
|
||||||
lamportsPerSignature: 42,
|
lamportsPerSignature: 42,
|
||||||
@ -32,5 +36,6 @@ export function mockGetRecentBlockhash(commitment: ?Commitment) {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,12 @@ test('create and query nonce account', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: minimumAmount * 2,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: minimumAmount * 2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -104,6 +109,10 @@ test('create and query nonce account', async () => {
|
|||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: {
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: {
|
||||||
owner: [
|
owner: [
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -143,6 +152,7 @@ test('create and query nonce account', async () => {
|
|||||||
executable: false,
|
executable: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
//
|
//
|
||||||
const nonceAccountData = await connection.getNonce(
|
const nonceAccountData = await connection.getNonce(
|
||||||
|
@ -98,7 +98,12 @@ test('transaction-payer', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: true,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -139,7 +144,12 @@ test('transaction-payer', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: 99,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: 99,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -158,7 +168,12 @@ test('transaction-payer', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
result: 2,
|
result: {
|
||||||
|
context: {
|
||||||
|
slot: 11,
|
||||||
|
},
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
expect(await connection.getBalance(accountFrom.publicKey)).toBe(2);
|
expect(await connection.getBalance(accountFrom.publicKey)).toBe(2);
|
||||||
|
Reference in New Issue
Block a user