Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use archival rpc calls if the block id is specified #419

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading