Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit d527e39

Browse files
committed
fix: adapt to binary64 RPC encoding change
1 parent de736e0 commit d527e39

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

web3.js/src/connection.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ const GetTokenAccountsByOwner = jsonRpcResultAndContext(
713713
executable: 'boolean',
714714
owner: 'string',
715715
lamports: 'number',
716-
data: 'string',
716+
data: ['string', struct.literal('binary64')],
717717
rentEpoch: 'number?',
718718
}),
719719
}),
@@ -795,7 +795,7 @@ const ParsedAccountInfoResult = struct.object({
795795
owner: 'string',
796796
lamports: 'number',
797797
data: struct.union([
798-
'string',
798+
['string', struct.literal('binary64')],
799799
struct.pick({
800800
program: 'string',
801801
parsed: 'any',
@@ -1631,15 +1631,18 @@ export class Connection {
16311631

16321632
return {
16331633
context,
1634-
value: value.map(result => ({
1635-
pubkey: new PublicKey(result.pubkey),
1636-
account: {
1637-
executable: result.account.executable,
1638-
owner: new PublicKey(result.account.owner),
1639-
lamports: result.account.lamports,
1640-
data: Buffer.from(result.account.data, 'base64'),
1641-
},
1642-
})),
1634+
value: value.map(result => {
1635+
assert(result.account.data[1] === 'binary64');
1636+
return {
1637+
pubkey: new PublicKey(result.pubkey),
1638+
account: {
1639+
executable: result.account.executable,
1640+
owner: new PublicKey(result.account.owner),
1641+
lamports: result.account.lamports,
1642+
data: Buffer.from(result.account.data[0], 'base64'),
1643+
},
1644+
};
1645+
}),
16431646
};
16441647
}
16451648

@@ -1769,11 +1772,12 @@ export class Connection {
17691772
let value = null;
17701773
if (res.result.value) {
17711774
const {executable, owner, lamports, data} = res.result.value;
1775+
assert(data[1] === 'binary64');
17721776
value = {
17731777
executable,
17741778
owner: new PublicKey(owner),
17751779
lamports,
1776-
data: Buffer.from(data, 'base64'),
1780+
data: Buffer.from(data[0], 'base64'),
17771781
};
17781782
}
17791783

@@ -1817,7 +1821,8 @@ export class Connection {
18171821

18181822
let data = resultData;
18191823
if (!data.program) {
1820-
data = Buffer.from(data, 'base64');
1824+
assert(data[1] === 'binary64');
1825+
data = Buffer.from(data[0], 'base64');
18211826
}
18221827

18231828
value = {
@@ -1881,13 +1886,14 @@ export class Connection {
18811886
assert(typeof result !== 'undefined');
18821887

18831888
return result.map(result => {
1889+
assert(result.account.data[1] === 'binary64');
18841890
return {
18851891
pubkey: new PublicKey(result.pubkey),
18861892
account: {
18871893
executable: result.account.executable,
18881894
owner: new PublicKey(result.account.owner),
18891895
lamports: result.account.lamports,
1890-
data: Buffer.from(result.account.data, 'base64'),
1896+
data: Buffer.from(result.account.data[0], 'base64'),
18911897
},
18921898
};
18931899
});
@@ -1931,7 +1937,8 @@ export class Connection {
19311937

19321938
let data = resultData;
19331939
if (!data.program) {
1934-
data = Buffer.from(data, 'base64');
1940+
assert(data[1] === 'binary64');
1941+
data = Buffer.from(data[0], 'base64');
19351942
}
19361943

19371944
return {
@@ -2899,14 +2906,15 @@ export class Connection {
28992906
const {result} = res;
29002907
const {value, context} = result;
29012908

2909+
assert(value.account.data[1] === 'binary64');
29022910
sub.callback(
29032911
{
29042912
accountId: value.pubkey,
29052913
accountInfo: {
29062914
executable: value.account.executable,
29072915
owner: new PublicKey(value.account.owner),
29082916
lamports: value.account.lamports,
2909-
data: Buffer.from(value.account.data, 'base64'),
2917+
data: Buffer.from(value.account.data[0], 'base64'),
29102918
},
29112919
},
29122920
context,

web3.js/test/connection.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ test('get program accounts', async () => {
263263
result: [
264264
{
265265
account: {
266-
data: '',
266+
data: ['', 'binary64'],
267267
executable: false,
268268
lamports: LAMPORTS_PER_SOL - feeCalculator.lamportsPerSignature,
269269
owner: programId.publicKey.toBase58(),
@@ -273,7 +273,7 @@ test('get program accounts', async () => {
273273
},
274274
{
275275
account: {
276-
data: '',
276+
data: ['', 'binary64'],
277277
executable: false,
278278
lamports:
279279
0.5 * LAMPORTS_PER_SOL - feeCalculator.lamportsPerSignature,
@@ -1693,7 +1693,7 @@ test('request airdrop', async () => {
16931693
value: {
16941694
owner: '11111111111111111111111111111111',
16951695
lamports: minimumAmount + 42,
1696-
data: '',
1696+
data: ['', 'binary64'],
16971697
executable: false,
16981698
},
16991699
},
@@ -1727,7 +1727,7 @@ test('request airdrop', async () => {
17271727
value: {
17281728
owner: '11111111111111111111111111111111',
17291729
lamports: minimumAmount + 42,
1730-
data: '',
1730+
data: ['', 'binary64'],
17311731
executable: false,
17321732
},
17331733
},

web3.js/test/nonce.test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ if (!mockRpcEnabled) {
1414
jest.setTimeout(30000);
1515
}
1616

17-
const expectedData = (authorizedPubkey: PublicKey): string => {
17+
const expectedData = (authorizedPubkey: PublicKey): [string, string] => {
1818
const expectedData = Buffer.alloc(NONCE_ACCOUNT_LENGTH);
1919
expectedData.writeInt32LE(0, 0); // Version, 4 bytes
2020
expectedData.writeInt32LE(1, 4); // State, 4 bytes
2121
authorizedPubkey.toBuffer().copy(expectedData, 8); // authorizedPubkey, 32 bytes
2222
const mockNonce = new Account();
2323
mockNonce.publicKey.toBuffer().copy(expectedData, 40); // Hash, 32 bytes
2424
expectedData.writeUInt16LE(5000, 72); // feeCalculator, 8 bytes
25-
return expectedData.toString('base64');
25+
return [expectedData.toString('base64'), 'binary64'];
2626
};
2727

2828
test('create and query nonce account', async () => {
@@ -119,7 +119,10 @@ test('create and query nonce account', async () => {
119119
url,
120120
{
121121
method: 'getAccountInfo',
122-
params: [nonceAccount.publicKey.toBase58(), {commitment: 'recent'}],
122+
params: [
123+
nonceAccount.publicKey.toBase58(),
124+
{encoding: 'binary64', commitment: 'recent'},
125+
],
123126
},
124127
{
125128
error: null,
@@ -243,7 +246,10 @@ test('create and query nonce account with seed', async () => {
243246
url,
244247
{
245248
method: 'getAccountInfo',
246-
params: [noncePubkey.toBase58(), {commitment: 'recent'}],
249+
params: [
250+
noncePubkey.toBase58(),
251+
{encoding: 'binary64', commitment: 'recent'},
252+
],
247253
},
248254
{
249255
error: null,

0 commit comments

Comments
 (0)