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

add rpc for light client proof #337

Merged
merged 9 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions lib/providers/json-rpc-provider.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions lib/providers/json-rpc-provider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions lib/providers/provider.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion lib/providers/provider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/providers/json-rpc-provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Provider, FinalExecutionOutcome, NodeStatusResult, BlockId,
BlockResult, ChunkId, ChunkResult, adaptTransactionResult, EpochValidatorInfo,
GenesisConfig
GenesisConfig, LightClientProof, LightClientProofRequest
} from './provider';
import { Network } from '../utils/network';
import { ConnectionInfo, fetchJson } from '../utils/web';
Expand Down Expand Up @@ -115,12 +115,20 @@ export class JsonRpcProvider extends Provider {
return await this.sendJsonRpc('EXPERIMENTAL_genesis_config', []);
}

/**
* Gets EXPERIMENTAL_light_client_proof from RPC
bowenwang1996 marked this conversation as resolved.
Show resolved Hide resolved
* @returns {Promise<LightClientProof>}
*/
async experimental_lightClientProof(request: LightClientProofRequest): Promise<LightClientProof> {
return await this.sendJsonRpc('EXPERIMENTAL_light_client_proof', request);
}

/**
* Directly call the RPC specifying the method and params
* @param method RPC method
* @param params Parameters to the method
*/
async sendJsonRpc(method: string, params: any[]): Promise<any> {
async sendJsonRpc(method: string, params: any): Promise<any> {
const request = {
method,
params,
Expand Down
53 changes: 53 additions & 0 deletions src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export interface ExecutionOutcome {
status: ExecutionStatus | ExecutionStatusBasic;
}

export interface ExecutionOutcomeWithIdView {
proof: MerklePath;
block_hash: string;
id: string;
outcome: ExecutionOutcome;
}

export interface FinalExecutionOutcome {
status: FinalExecutionStatus | FinalExecutionStatusBasic;
transaction: any;
Expand Down Expand Up @@ -181,6 +188,51 @@ export interface EpochValidatorInfo {
epoch_start_height: number;
}

export interface MerkleNode {
hash: string;
direction: string;
}

export type MerklePath = MerkleNode[];

export interface BlockHeaderInnerLiteView {
height: number;
epoch_id: string;
next_epoch_id: string;
prev_state_root: string;
outcome_root: string;
timestamp: number;
next_bp_hash: string;
block_merkle_root: string;
}

export interface LightClientBlockLiteView {
prev_block_hash: string;
inner_rest_hash: string;
inner_lite: BlockHeaderInnerLiteView;
}

export interface LightClientProof {
outcome_proof: ExecutionOutcomeWithIdView;
outcome_root_proof: MerklePath;
block_header_lite: LightClientBlockLiteView;
block_proof: MerklePath;
}

export enum IdType {
Transaction = 'transaction',
Receipt = 'receipt',
}

export interface LightClientProofRequest {
type: IdType;
light_client_head: string;
transaction_hash?: string;
sender_id?: string;
receipt_id?: string;
receiver_id?: string;
}

export abstract class Provider {
abstract async getNetwork(): Promise<Network>;
abstract async status(): Promise<NodeStatusResult>;
Expand All @@ -192,6 +244,7 @@ export abstract class Provider {
abstract async chunk(chunkId: ChunkId): Promise<ChunkResult>;
abstract async validators(blockId: BlockId): Promise<EpochValidatorInfo>;
abstract async experimental_genesisConfig(): Promise<GenesisConfig>;
abstract async experimental_lightClientProof(request: LightClientProofRequest): Promise<LightClientProof>;
}

export function getTransactionLastResult(txResult: FinalExecutionOutcome): any {
Expand Down