Skip to content

Commit

Permalink
Use archival rpc calls if the block id is specified (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelisnear authored Apr 17, 2024
1 parent 4d98c9b commit 7b737fe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/social-db/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const MAINNET_SOCIAL_CONTRACT_ID = 'social.near';

export const TESTNET_RPC_URL = 'https://rpc.testnet.near.org';
export const MAINNET_RPC_URL = 'https://rpc.mainnet.near.org';
export const ARCHIVAL_MAINNET_RPC_URL = 'https://archival-rpc.mainnet.near.org';
export const ARCHIVAL_TESTNET_RPC_URL = 'https://archival-rpc.testnet.near.org';

export const SOCIAL_COMPONENT_NAMESPACE = 'component_alpha';
export const SOCIAL_IPFS_BASE_URL = 'https://ipfs.near.social/ipfs';
Expand Down
22 changes: 21 additions & 1 deletion packages/social-db/src/social-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type {
import { Big } from 'big.js';

import {
ARCHIVAL_MAINNET_RPC_URL,
ARCHIVAL_TESTNET_RPC_URL,
EXTRA_STORAGE_BALANCE,
INITIAL_ACCOUNT_STORAGE_BALANCE,
MAINNET_RPC_URL,
Expand Down Expand Up @@ -50,6 +52,8 @@ export class SocialDb {

private testnetProvider: JsonRpcProvider;
private mainnetProvider: JsonRpcProvider;
private archivalMainnetProvider: JsonRpcProvider;
private archivalTestnetProvider: JsonRpcProvider;

/**
* Interact with the `social.near` contract (Social DB).
Expand Down Expand Up @@ -77,6 +81,14 @@ export class SocialDb {
this.mainnetProvider = new JsonRpcProvider({
url: MAINNET_RPC_URL,
});

this.archivalMainnetProvider = new JsonRpcProvider({
url: ARCHIVAL_MAINNET_RPC_URL,
});

this.archivalTestnetProvider = new JsonRpcProvider({
url: ARCHIVAL_TESTNET_RPC_URL,
});
}

private get contractId() {
Expand All @@ -94,6 +106,11 @@ export class SocialDb {
return this.testnetProvider;
}

private get archivalProvider() {
if (this.networkId === 'mainnet') return this.archivalMainnetProvider;
return this.archivalTestnetProvider;
}

private get walletSelectorState() {
return this.walletSelector?.store.getState() ?? null;
}
Expand Down Expand Up @@ -399,7 +416,10 @@ export class SocialDb {
}

try {
const response = await this.provider.query<CodeResult>(request);
const response = await (blockId
? this.archivalProvider
: this.provider
).query<CodeResult>(request);
const responseData = parseJsonRpcResponse(response.result) as T;

this.log({
Expand Down

0 comments on commit 7b737fe

Please sign in to comment.