Skip to content

Commit 97ccbbd

Browse files
committed
v2.1.26
Added Retrieve Gas Balance and Retrieve Automatic Gas Records for Transactions interfaces
1 parent 652c211 commit 97ccbbd

File tree

3 files changed

+133
-2
lines changed

3 files changed

+133
-2
lines changed

.github/workflows/release-npm.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Release
2-
on: workflow_dispatch
2+
on:
3+
push:
4+
branches:
5+
- main
36

47
jobs:
58
maybe-release:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@safeheron/api-sdk",
3-
"version": "1.0.19",
3+
"version": "1.0.20",
44
"description": "Javascript & Typescript SDK for Safeheron API",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

src/safeheron/gasApi.ts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import {SafeheronClient} from '../safeheron';
2+
import {SafeheronConfig} from "../config";
3+
4+
export interface GasStatusResponse {
5+
/**
6+
* Gas Balance
7+
*/
8+
gasBalance: Array<GasBalance>;
9+
}
10+
11+
export interface GasBalance {
12+
/**
13+
* Coin
14+
*/
15+
symbol: string;
16+
17+
/**
18+
* Balance
19+
*/
20+
amount: string;
21+
}
22+
23+
24+
export interface GasTransactionsGetByTxKeyRequest {
25+
/**
26+
* Transaction key, obtained from transactions created via the Create a Transaction V3 API, App, or Web Console.
27+
*/
28+
txKey: string;
29+
}
30+
31+
export interface GasTransactionsGetByTxKeyResponse {
32+
/**
33+
* Transaction key
34+
*/
35+
txKey: string;
36+
37+
/**
38+
* Transaction fee coin
39+
*/
40+
symbol: string;
41+
42+
/**
43+
* Total fee amount. A single transaction may have multiple Gas records; the total fee paid is the sum of all records with SUCCESS and FAILURE_GAS_CONSUMED statuses.
44+
*/
45+
totalAmount: string;
46+
47+
/**
48+
* Gas records
49+
*/
50+
detailList: Array<Detail>;
51+
}
52+
53+
54+
55+
56+
export interface Detail {
57+
/**
58+
* Energy rental transaction Key
59+
*/
60+
gasServiceTxKey: string;
61+
62+
/**
63+
* Transaction fee coin
64+
*/
65+
symbol: string;
66+
67+
/**
68+
* Amount
69+
*/
70+
amount: string;
71+
72+
/**
73+
* Balance after paying the fee
74+
*/
75+
balance: string;
76+
77+
/**
78+
* SUCCESS: Gas successful
79+
* FAILURE_GAS_REFUNDED: Gas failed, refunded
80+
* FAILURE_GAS_CONSUMED: Gas failed, but fees were incurred
81+
*/
82+
status: string;
83+
84+
/**
85+
* Gas resource type, only valid for TRON network:
86+
* ENERGY
87+
* BANDWIDTH
88+
*/
89+
resourceType: string;
90+
91+
/**
92+
* Gas deduction time, UNIX timestamp in milliseconds
93+
*/
94+
timestamp: string;
95+
}
96+
97+
export class GasApi {
98+
99+
private client: SafeheronClient;
100+
101+
constructor(config: SafeheronConfig) {
102+
this.client = new SafeheronClient({
103+
baseUrl: config.baseUrl,
104+
apiKey: config.apiKey,
105+
rsaPrivateKey: config.rsaPrivateKey,
106+
safeheronRsaPublicKey: config.safeheronRsaPublicKey,
107+
requestTimeout: config.requestTimeout
108+
});
109+
}
110+
111+
112+
/**
113+
* Retrieve Gas Balance
114+
* Retrieve your Gas balance for the TRON energy rental service.
115+
*/
116+
async gasStatus(): Promise<GasStatusResponse> {
117+
return await this.client.doRequest<null, GasStatusResponse>('/v1/gas/status', null);
118+
}
119+
120+
121+
/**
122+
* Retrieve Automatic Gas Records for Transactions
123+
* When the TRON energy rental service is enabled, Safeheron automatically tops up the required Gas fees for TRON network transactions. This API allows you to query the energy rental records used by a transaction. A single transaction may have multiple records. The actual Gas fee consumed by the transaction is the sum of all records with SUCCESS and FAILURE_GAS_CONSUMED statuses.
124+
*/
125+
async gasTransactionsGetByTxKey(request: GasTransactionsGetByTxKeyRequest): Promise<GasTransactionsGetByTxKeyResponse> {
126+
return await this.client.doRequest<GasTransactionsGetByTxKeyRequest, GasTransactionsGetByTxKeyResponse>('/v1/gas/transactions/getByTxKey', request);
127+
}
128+
}

0 commit comments

Comments
 (0)