Skip to content

Commit 9a8bae6

Browse files
Merge pull request #504 from casper-ecosystem/CSDK-214
Add new get auction info v2 method support
2 parents 160d080 + acfb7f0 commit 9a8bae6

19 files changed

+1391
-95
lines changed

src/rpc/client.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
RpcResponse,
2323
StateGetAccountInfo,
2424
StateGetAuctionInfoResult,
25+
StateGetAuctionInfoV1Result,
2526
StateGetBalanceResult,
2627
StateGetDictionaryResult,
2728
StateGetEntityResult,
@@ -38,14 +39,86 @@ import {
3839
import { Deploy, PublicKey, Transaction } from '../types';
3940

4041
export interface ClientPOS {
42+
/**
43+
* Retrieves the latest auction information, including Validator Bids and Era Validators.
44+
* @returns A Promise resolving to the latest auction info.
45+
* @rpc state_get_auction_info_v2 (fallback: state_get_auction_info)
46+
*/
4147
getLatestAuctionInfo(): Promise<StateGetAuctionInfoResult>;
48+
49+
/**
50+
* Retrieves auction information by block hash, including Validator Bids and Era Validators.
51+
* @param blockHash - The hash of the block to retrieve auction info for.
52+
* @returns A Promise resolving to the auction info.
53+
* @rpc state_get_auction_info_v2 (fallback: state_get_auction_info)
54+
*/
4255
getAuctionInfoByHash(blockHash: string): Promise<StateGetAuctionInfoResult>;
56+
57+
/**
58+
* Retrieves auction information by block height, including Validator Bids and Era Validators.
59+
* @param height - The height of the block to retrieve auction info for.
60+
* @returns A Promise resolving to the auction info.
61+
* @rpc state_get_auction_info_v2 (fallback: state_get_auction_info)
62+
*/
4363
getAuctionInfoByHeight(height: number): Promise<StateGetAuctionInfoResult>;
4464

65+
/**
66+
* Retrieves the latest auction information (version 1), including Validator Bids and Era Validators.
67+
* @returns A Promise resolving to the latest auction info (V1).
68+
* @rpc state_get_auction_info
69+
*/
70+
getLatestAuctionInfoV1(): Promise<StateGetAuctionInfoV1Result>;
71+
72+
/**
73+
* Retrieves auction information by block hash (version 1), including Validator Bids and Era Validators.
74+
* @param blockHash - The hash of the block to retrieve auction info for.
75+
* @returns A Promise resolving to the auction info (V1).
76+
* @rpc state_get_auction_info
77+
*/
78+
getAuctionInfoV1ByHash(
79+
blockHash: string
80+
): Promise<StateGetAuctionInfoV1Result>;
81+
82+
/**
83+
* Retrieves auction information by block height (version 1), including Validator Bids and Era Validators.
84+
* @param height - The height of the block to retrieve auction info for.
85+
* @returns A Promise resolving to the auction info (V1).
86+
* @rpc state_get_auction_info
87+
*/
88+
getAuctionInfoV1ByHeight(
89+
height: number
90+
): Promise<StateGetAuctionInfoV1Result>;
91+
92+
/**
93+
* Retrieves the latest EraInfo from the network.
94+
* Only the last block in an era (switch block) contains an era summary.
95+
* This method returns information about the latest block, which may not be the last block in the era.
96+
* @returns A Promise resolving to the latest EraInfo.
97+
*/
4598
getEraInfoLatest(): Promise<ChainGetEraInfoResult>;
99+
100+
/**
101+
* Retrieves EraInfo by block height.
102+
* Only the last block in an era (switch block) contains an era summary.
103+
* @param height - The height of the block to retrieve EraInfo for.
104+
* @returns A Promise resolving to the EraInfo.
105+
*/
46106
getEraInfoByBlockHeight(height: number): Promise<ChainGetEraInfoResult>;
107+
108+
/**
109+
* Retrieves EraInfo by block hash.
110+
* Only the last block in an era (switch block) contains an era summary.
111+
* @param hash - The hash of the block to retrieve EraInfo for.
112+
* @returns A Promise resolving to the EraInfo.
113+
*/
47114
getEraInfoByBlockHash(hash: string): Promise<ChainGetEraInfoResult>;
48115

116+
/**
117+
* Retrieves status changes of active validators.
118+
* The changes occurred during the EraId contained within the response itself.
119+
* A validator may show more than one change in a single era.
120+
* @returns A Promise resolving to validator status changes.
121+
*/
49122
getValidatorChangesInfo(): Promise<InfoGetValidatorChangesResult>;
50123
}
51124

src/rpc/request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export enum Method {
2626
GetBlockTransfers = 'chain_get_block_transfers',
2727
GetEraSummary = 'chain_get_era_summary',
2828
GetAuctionInfo = 'state_get_auction_info',
29+
GetAuctionInfoV2 = 'state_get_auction_info_v2',
2930
GetValidatorChanges = 'info_get_validator_changes',
3031
GetStateRootHash = 'chain_get_state_root_hash',
3132
GetStatus = 'info_get_status',

src/rpc/response.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
Hash,
3535
PublicKey,
3636
CLValueUInt512,
37+
AuctionStateV1,
38+
AuctionStateV2,
3739
AddressableEntity
3840
} from '../types';
3941

@@ -63,6 +65,28 @@ export class StateGetAuctionInfoResult {
6365
rawJSON?: any;
6466
}
6567

68+
@jsonObject
69+
export class StateGetAuctionInfoV1Result {
70+
@jsonMember({ name: 'api_version', constructor: String })
71+
version: string;
72+
73+
@jsonMember({ name: 'auction_state', constructor: AuctionStateV1 })
74+
auctionState: AuctionStateV1;
75+
76+
rawJSON?: any;
77+
}
78+
79+
@jsonObject
80+
export class StateGetAuctionInfoV2Result {
81+
@jsonMember({ name: 'api_version', constructor: String })
82+
version: string;
83+
84+
@jsonMember({ name: 'auction_state', constructor: AuctionStateV2 })
85+
auctionState: AuctionStateV2;
86+
87+
rawJSON?: any;
88+
}
89+
6690
@jsonObject
6791
export class StateGetBalanceResult {
6892
@jsonMember({ name: 'api_version', constructor: String })

src/rpc/rpc_client.ts

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
RpcResponse,
2525
StateGetAccountInfo,
2626
StateGetAuctionInfoResult,
27+
StateGetAuctionInfoV1Result,
28+
StateGetAuctionInfoV2Result,
2729
StateGetBalanceResult,
2830
StateGetDictionaryResult,
2931
StateGetEntityResult,
@@ -61,7 +63,8 @@ import {
6163
Deploy,
6264
PublicKey,
6365
Hash,
64-
Transaction
66+
Transaction,
67+
AuctionState
6568
} from '../types';
6669
import { HttpError } from './error';
6770

@@ -773,9 +776,45 @@ export class RpcClient implements IClient {
773776
}
774777

775778
async getLatestAuctionInfo(): Promise<StateGetAuctionInfoResult> {
779+
try {
780+
const auctionInfoV2 = await this.getLatestAuctionInfoV2();
781+
const auctionInfoResult = new StateGetAuctionInfoResult();
782+
auctionInfoResult.auctionState = AuctionState.fromV2(
783+
auctionInfoV2.auctionState
784+
);
785+
auctionInfoResult.version = auctionInfoV2.version;
786+
auctionInfoResult.rawJSON = auctionInfoV2.rawJSON;
787+
return auctionInfoResult;
788+
} catch (err) {
789+
const errorMessage = err?.message || '';
790+
if (!errorMessage.includes('Method not found')) {
791+
throw err;
792+
}
793+
794+
const auctionInfoV1 = await this.getLatestAuctionInfoV1();
795+
const auctionInfoResult = new StateGetAuctionInfoResult();
796+
auctionInfoResult.auctionState = AuctionState.fromV1(
797+
auctionInfoV1.auctionState
798+
);
799+
auctionInfoResult.version = auctionInfoV1.version;
800+
auctionInfoResult.rawJSON = auctionInfoV1.rawJSON;
801+
return auctionInfoResult;
802+
}
803+
}
804+
805+
async getLatestAuctionInfoV1(): Promise<StateGetAuctionInfoV1Result> {
776806
const resp = await this.processRequest(Method.GetAuctionInfo, null);
777807

778-
const result = this.parseResponse(StateGetAuctionInfoResult, resp.result);
808+
const result = this.parseResponse(StateGetAuctionInfoV1Result, resp.result);
809+
result.rawJSON = resp.result;
810+
811+
return result;
812+
}
813+
814+
async getLatestAuctionInfoV2(): Promise<StateGetAuctionInfoV2Result> {
815+
const resp = await this.processRequest(Method.GetAuctionInfoV2, null);
816+
817+
const result = this.parseResponse(StateGetAuctionInfoV2Result, resp.result);
779818
result.rawJSON = resp.result;
780819

781820
return result;
@@ -784,6 +823,31 @@ export class RpcClient implements IClient {
784823
async getAuctionInfoByHash(
785824
blockHash: string
786825
): Promise<StateGetAuctionInfoResult> {
826+
try {
827+
const resV2 = await this.getAuctionInfoV2ByHash(blockHash);
828+
const result = new StateGetAuctionInfoResult();
829+
result.auctionState = AuctionState.fromV2(resV2.auctionState);
830+
result.version = resV2.version;
831+
result.rawJSON = resV2.rawJSON;
832+
return result;
833+
} catch (err) {
834+
const errorMessage = err?.message || '';
835+
if (!errorMessage.includes('Method not found')) {
836+
throw err;
837+
}
838+
839+
const resV1 = await this.getAuctionInfoV1ByHash(blockHash);
840+
const result = new StateGetAuctionInfoResult();
841+
result.auctionState = AuctionState.fromV1(resV1.auctionState);
842+
result.version = resV1.version;
843+
result.rawJSON = resV1.rawJSON;
844+
return result;
845+
}
846+
}
847+
848+
async getAuctionInfoV1ByHash(
849+
blockHash: string
850+
): Promise<StateGetAuctionInfoV1Result> {
787851
const serializer = new TypedJSON(ParamBlockIdentifier);
788852
const blockIdentifierParam = ParamBlockIdentifier.byHash(blockHash);
789853

@@ -792,7 +856,24 @@ export class RpcClient implements IClient {
792856
serializer.toPlainJson(blockIdentifierParam) as ParamBlockIdentifier
793857
);
794858

795-
const result = this.parseResponse(StateGetAuctionInfoResult, resp.result);
859+
const result = this.parseResponse(StateGetAuctionInfoV1Result, resp.result);
860+
result.rawJSON = resp.result;
861+
862+
return result;
863+
}
864+
865+
async getAuctionInfoV2ByHash(
866+
blockHash: string
867+
): Promise<StateGetAuctionInfoV2Result> {
868+
const serializer = new TypedJSON(ParamBlockIdentifier);
869+
const blockIdentifierParam = ParamBlockIdentifier.byHash(blockHash);
870+
871+
const resp = await this.processRequest(
872+
Method.GetAuctionInfoV2,
873+
serializer.toPlainJson(blockIdentifierParam) as ParamBlockIdentifier
874+
);
875+
876+
const result = this.parseResponse(StateGetAuctionInfoV2Result, resp.result);
796877
result.rawJSON = resp.result;
797878

798879
return result;
@@ -801,6 +882,31 @@ export class RpcClient implements IClient {
801882
async getAuctionInfoByHeight(
802883
height: number
803884
): Promise<StateGetAuctionInfoResult> {
885+
try {
886+
const resV2 = await this.getAuctionInfoV2ByHeight(height);
887+
const result = new StateGetAuctionInfoResult();
888+
result.auctionState = AuctionState.fromV2(resV2.auctionState);
889+
result.version = resV2.version;
890+
result.rawJSON = resV2.rawJSON;
891+
return result;
892+
} catch (err) {
893+
const errorMessage = err?.message || '';
894+
if (!errorMessage.includes('Method not found')) {
895+
throw err;
896+
}
897+
898+
const resV1 = await this.getAuctionInfoV1ByHeight(height);
899+
const result = new StateGetAuctionInfoResult();
900+
result.auctionState = AuctionState.fromV1(resV1.auctionState);
901+
result.version = resV1.version;
902+
result.rawJSON = resV1.rawJSON;
903+
return result;
904+
}
905+
}
906+
907+
async getAuctionInfoV1ByHeight(
908+
height: number
909+
): Promise<StateGetAuctionInfoV1Result> {
804910
const serializer = new TypedJSON(ParamBlockIdentifier);
805911
const blockIdentifierParam = ParamBlockIdentifier.byHeight(height);
806912

@@ -809,7 +915,24 @@ export class RpcClient implements IClient {
809915
serializer.toPlainJson(blockIdentifierParam) as ParamBlockIdentifier
810916
);
811917

812-
const result = this.parseResponse(StateGetAuctionInfoResult, resp.result);
918+
const result = this.parseResponse(StateGetAuctionInfoV1Result, resp.result);
919+
result.rawJSON = resp.result;
920+
921+
return result;
922+
}
923+
924+
async getAuctionInfoV2ByHeight(
925+
height: number
926+
): Promise<StateGetAuctionInfoV2Result> {
927+
const serializer = new TypedJSON(ParamBlockIdentifier);
928+
const blockIdentifierParam = ParamBlockIdentifier.byHeight(height);
929+
930+
const resp = await this.processRequest(
931+
Method.GetAuctionInfoV2,
932+
serializer.toPlainJson(blockIdentifierParam) as ParamBlockIdentifier
933+
);
934+
935+
const result = this.parseResponse(StateGetAuctionInfoV2Result, resp.result);
813936
result.rawJSON = resp.result;
814937

815938
return result;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"bonding_purse": "uref-b3c03358245a0d9514064b6d0c3dd90023d29a0fe137507d430a26990f5ce8e3-007",
3+
"staked_amount": "900000000000",
4+
"delegation_rate": 10,
5+
"delegators": [
6+
{
7+
"public_key": "01d829cbfb66b2b11ef8d8feb6d3f2155789fc22f407bb57f89b05f6ba4b9ae070",
8+
"staked_amount": "555000000000",
9+
"bonding_purse": "uref-41059a3aa5c5759c7f5e3c826cb47e0b21257ac57ee63a4c00dc305133e55d64-007",
10+
"delegatee": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61"
11+
}
12+
],
13+
"inactive": false
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"validator_public_key": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61",
3+
"bonding_purse": "uref-fafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa-007",
4+
"staked_amount": "900000000000",
5+
"delegation_rate": 0,
6+
"vesting_schedule": null,
7+
"delegators": [
8+
{
9+
"delegator_public_key": "014508a07aa941707f3eb2db94c8897a80b2c1197476b6de213ac273df7d86c4ff",
10+
"delegator": {
11+
"delegator_kind": {
12+
"PublicKey": "01d829cbfb66b2b11ef8d8feb6d3f2155789fc22f407bb57f89b05f6ba4b9ae070"
13+
},
14+
"staked_amount": "10",
15+
"bonding_purse": "uref-fbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfb-007",
16+
"validator_public_key": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61",
17+
"vesting_schedule": null
18+
}
19+
}
20+
],
21+
"inactive": false
22+
}

src/tests/data/bid/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import auctionBidV1Json from './auction_bid_example_v1.json';
2+
import auctionBidV2Json from './auction_bid_example_v2.json';
3+
import storedBidJson from './stored_bid_example.json';
4+
5+
export { auctionBidV1Json, auctionBidV2Json, storedBidJson };
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"validator_public_key": "01018525deae6091abccab6704a0fa44e12c495eec9e8fe6929862e1b75580e715",
3+
"bonding_purse": "uref-7f9a0dae980f0bb2cb37449f74095843e14ed1b79b3ce9f0a7b1611c30eb10d9-007",
4+
"staked_amount": "1196098880899",
5+
"delegation_rate": 10,
6+
"vesting_schedule": null,
7+
"delegators": {
8+
"014832ab8c1822bca82f75581d0e476ef9833a8536977db8f11324a39544c11dc5": {
9+
"delegator_public_key": "014832ab8c1822bca82f75581d0e476ef9833a8536977db8f11324a39544c11dc5",
10+
"staked_amount": "594256548131",
11+
"bonding_purse": "uref-b3749a7f7a8c187bb983f64601bf573580a4d0f013dacddc9044453daed0bcb4-007",
12+
"validator_public_key": "01018525deae6091abccab6704a0fa44e12c495eec9e8fe6929862e1b75580e715",
13+
"vesting_schedule": null
14+
},
15+
"01e6eb2475f3d978afae6efe6da3434141cf24d2d3e2523ca0d790ff8b08baee05": {
16+
"delegator_public_key": "01e6eb2475f3d978afae6efe6da3434141cf24d2d3e2523ca0d790ff8b08baee05",
17+
"staked_amount": "2421183792212",
18+
"bonding_purse": "uref-befe1d9e57a748f115ae926af4267d70beefde6d217e1fbcb96a244e18f332fd-007",
19+
"validator_public_key": "01018525deae6091abccab6704a0fa44e12c495eec9e8fe6929862e1b75580e715",
20+
"vesting_schedule": null
21+
}
22+
},
23+
"inactive": false
24+
}

src/tests/data/era/era_summary_example.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)