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

algod: Add blockOffsetTimestamp, syncRound APIs to algod client #769

Merged
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
100 changes: 100 additions & 0 deletions src/client/v2/algod/algod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ import {
} from '../../urlTokenBaseHTTPClient';
import LightBlockHeaderProof from './lightBlockHeaderProof';
import StateProof from './stateproof';
import SetSyncRound from './setSyncRound';
import GetSyncRound from './getSyncRound';
import SetBlockOffsetTimestamp from './setBlockOffsetTimestamp';
import GetBlockOffsetTimestamp from './getBlockOffsetTimestamp';
import Disassemble from './disassemble';
import SimulateRawTransactions from './simulateTransaction';
import { EncodedSignedTransaction } from '../../../types';
import * as encoding from '../../../encoding/encoding';
import Ready from './ready';
import UnsetSyncRound from './unsetSyncRound';

/**
* 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 @@ -651,4 +657,98 @@ export default class AlgodClient extends ServiceClient {
simulateTransactions(request: modelsv2.SimulateRequest) {
return new SimulateRawTransactions(this.c, request);
}

/**
* Set the offset (in seconds) applied to the block timestamp when creating new blocks in devmode.
*
* #### Example
* ```typesecript
* const offset = 60
* await client.setBlockOffsetTimestamp(offset).do();
* ```
*
[Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#post-v2devmodeblocksoffsetoffset)
* @param offset
* @category POST
*/
setBlockOffsetTimestamp(offset: number) {
return new SetBlockOffsetTimestamp(this.c, this.intDecoding, offset);
}

/**
* Get the offset (in seconds) applied to the block timestamp when creating new blocks in devmode.
*
* #### Example
* ```typesecript
* const currentOffset = await client.getBlockOffsetTimestamp().do();
* ```
*
[Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2devmodeblocksoffset)
* @category GET
*/
getBlockOffsetTimestamp() {
return new GetBlockOffsetTimestamp(this.c, this.intDecoding);
}

/**
* Set the sync round on the ledger (algod must have EnableFollowMode: true), restricting catchup.
*
* #### Example
* ```typesecript
* const round = 10000
* await client.setSyncRound(round).do();
* ```
*
[Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#post-v2ledgersyncround)
* @param round
* @category POST
*/
setSyncRound(round: number) {
return new SetSyncRound(this.c, this.intDecoding, round);
}

/**
* Un-Set the sync round on the ledger (algod must have EnableFollowMode: true), removing the restriction on catchup.
*
* #### Example
* ```typesecript
* await client.unsetSyncRound().do();
* ```
*
[Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#delete-v2ledgersync)
* @category DELETE
*/
unsetSyncRound() {
return new UnsetSyncRound(this.c, this.intDecoding);
}

/**
* Get the current sync round on the ledger (algod must have EnableFollowMode: true).
*
* #### Example
* ```typesecript
* const currentSyncRound = await client.getSyncRound().do();
* ```
*
[Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2ledgersync)
* @category GET
*/
getSyncRound() {
return new GetSyncRound(this.c, this.intDecoding);
}

/**
* Ready check which returns 200 OK if algod is healthy and caught up
*
* #### Example
* ```typesecript
* await client.ready().do();
* ```
*
[Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-ready)
* @category GET
*/
ready() {
return new Ready(this.c, this.intDecoding);
}
}
17 changes: 17 additions & 0 deletions src/client/v2/algod/getBlockOffsetTimestamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import JSONRequest from '../jsonrequest';
import { GetBlockTimeStampOffsetResponse } from './models/types';

export default class GetBlockOffsetTimestamp extends JSONRequest<
GetBlockTimeStampOffsetResponse,
Record<string, any>
> {
// eslint-disable-next-line class-methods-use-this
path() {
return `/v2/devmode/blocks/offset`;
}

// eslint-disable-next-line class-methods-use-this
prepare(body: Record<string, any>): GetBlockTimeStampOffsetResponse {
return GetBlockTimeStampOffsetResponse.from_obj_for_encoding(body);
}
}
17 changes: 17 additions & 0 deletions src/client/v2/algod/getSyncRound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import JSONRequest from '../jsonrequest';
import { GetSyncRoundResponse } from './models/types';

export default class GetSyncRound extends JSONRequest<
GetSyncRoundResponse,
Record<string, any>
> {
// eslint-disable-next-line class-methods-use-this
path() {
return `/v2/ledger/sync`;
}

// eslint-disable-next-line class-methods-use-this
prepare(body: Record<string, any>): GetSyncRoundResponse {
return GetSyncRoundResponse.from_obj_for_encoding(body);
}
}
Loading