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

enhancement: Initial stateproofs support #629

Merged
merged 12 commits into from
Aug 29, 2022
44 changes: 39 additions & 5 deletions src/client/v2/algod/algod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ import AccountApplicationInformation from './accountApplicationInformation';
import Block from './block';
import Compile from './compile';
import Dryrun from './dryrun';
import Genesis from './genesis';
import GetAssetByID from './getAssetByID';
import GetApplicationByID from './getApplicationByID';
import HealthCheck from './healthCheck';
import PendingTransactionInformation from './pendingTransactionInformation';
import PendingTransactions from './pendingTransactions';
import PendingTransactionsByAddress from './pendingTransactionsByAddress';
import GetTransactionProof from './getTransactionProof';
import SendRawTransaction from './sendRawTransaction';
import Status from './status';
import StatusAfterBlock from './statusAfterBlock';
import SuggestedParams from './suggestedParams';
import Supply from './supply';
import Versions from './versions';
import Genesis from './genesis';
import Proof from './proof';
import { BaseHTTPClient } from '../../baseHTTPClient';
import {
AlgodTokenHeader,
CustomTokenHeader,
} from '../../urlTokenBaseHTTPClient';
import LightBlockHeaderProof from './lightBlockHeaderProof';
import StateProof from './stateproof';
tzaffi marked this conversation as resolved.
Show resolved Hide resolved

/**
* Algod client connects an application to the Algorand blockchain. The algod client requires a valid algod REST endpoint IP address and algod token from an Algorand node that is connected to the network you plan to interact with.
Expand Down Expand Up @@ -451,15 +453,47 @@ export default class AlgodClient extends ServiceClient {
* ```typescript
* const round = 18038133;
* const txId = "MEUOC4RQJB23CQZRFRKYEI6WBO73VTTPST5A7B3S5OKBUY6LFUDA";
* const proof = await algodClient.getProof(round, txId).do();
* const proof = await algodClient.getTransactionProof(round, txId).do();
* ```
*
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/v2/#get-v2blocksroundtransactionstxidproof)
* @param round - The round in which the transaction appears.
* @param txID - The transaction ID for which to generate a proof.
* @category GET
*/
getProof(round: number, txID: string) {
return new Proof(this.c, this.intDecoding, round, txID);
getTransactionProof(round: number, txID: string) {
return new GetTransactionProof(this.c, this.intDecoding, round, txID);
}

/**
* Gets a proof for a given light block header inside a state proof commitment.
*
* #### Example
* ```typescript
* const round = 11111111;
* const lightBlockHeaderProof = await algodClient.getLightBlockHeaderProof(round).do();
* ```
*
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/v2#get-v2blocksroundlightheaderproof)
* @param round
*/
getLightBlockHeaderProof(round: number) {
return new LightBlockHeaderProof(this.c, this.intDecoding, round);
}

/**
* Gets a state proof that covers a given round.
*
* #### Example
* ```typescript
* const round = 11111111;
* const stateProof = await algodClient.getStateProof(round).do();
* ```
*
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/v2#get-v2stateproofsround)
* @param round
*/
getStateProof(round: number) {
return new StateProof(this.c, this.intDecoding, round);
}
}
43 changes: 43 additions & 0 deletions src/client/v2/algod/getTransactionProof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';

export default class GetTransactionProof extends JSONRequest {
constructor(
c: HTTPClient,
intDecoding: IntDecoding,
private round: number,
private txID: string
) {
super(c, intDecoding);

this.round = round;
this.txID = txID;
}

path() {
return `/v2/blocks/${this.round}/transactions/${this.txID}/proof`;
}

/**
* Exclude assets and application data from results
* The type of hash function used to create the proof, must be one of: "sha512_256", "sha256"
*
* #### Example
* ```typescript
* const hashType = "sha256";
* const round = 123456;
* const txId = "abc123;
* const txProof = await algodClient.getTransactionProof(round, txId)
* .hashType(hashType)
* .do();
* ```
*
* @param hashType
* @category query
*/
hashType(hashType: string) {
this.query.hashtype = hashType;
return this;
}
}
15 changes: 15 additions & 0 deletions src/client/v2/algod/lightBlockHeaderProof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';

export default class LightBlockHeaderProof extends JSONRequest {
constructor(c: HTTPClient, intDecoding: IntDecoding, private round: number) {
super(c, intDecoding);

this.round = round;
}

path() {
return `/v2/blocks/${this.round}/lightheader/proof`;
}
}
Loading