Skip to content

Commit

Permalink
add api-key to lcd requests
Browse files Browse the repository at this point in the history
  • Loading branch information
markonmars committed Jun 26, 2024
1 parent b9e50af commit eae0493
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/bank/bank.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class BankService {

public async balance(address: AccAddress, height?: number): Promise<Coin[]> {
try {
const [balance] = await this.lcdService.bank.balance(address, { height })
const apikey = process.env.API_KEY
const [balance] = await this.lcdService.bank.balance(address, { height, 'x-apikey': apikey })

return Coin.fromTerraCoins(balance)
} catch (err) {
Expand All @@ -27,7 +28,9 @@ export class BankService {

public async total(height?: number): Promise<Coin[]> {
try {
const [total] = await this.lcdService.bank.total({ height })
const apikey = process.env.API_KEY

const [total] = await this.lcdService.bank.total({ height, 'x-apikey': apikey })

return Coin.fromTerraCoins(total)
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion src/ibc/ibc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class IbcService {

public async parameters(height?: number): Promise<IbcParams> {
try {
const result = await this.lcdService.ibcTransfer.parameters({ height })
const apikey = process.env.API_KEY
const result = await this.lcdService.ibcTransfer.parameters({ height, 'x-apikey': apikey })
return result
} catch (err) {
this.logger.error({ err }, 'Error getting parameters for %s.', height)
Expand Down
6 changes: 4 additions & 2 deletions src/staking/staking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ export class StakingService {

public async pool(height?: number): Promise<StakingPool> {
try {
const pool = await this.lcdService.staking.pool({ height })
const apikey = process.env.API_KEY
const pool = await this.lcdService.staking.pool({ height, 'x-apikey': apikey })

return {
bonded_tokens: Coin.fromTerraCoin(pool.bonded_tokens),
Expand All @@ -198,7 +199,8 @@ export class StakingService {

public async parameters(height?: number): Promise<StakingParams> {
try {
const params = await this.lcdService.staking.parameters({ height })
const apikey = process.env.API_KEY
const params = await this.lcdService.staking.parameters({ height, 'x-apikey': apikey })

return {
unbonding_time: params.unbonding_time.toString(),
Expand Down
12 changes: 8 additions & 4 deletions src/tendermint/tendermint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export class TendermintService {

public async nodeInfo(height?: number): Promise<NodeInfo> {
try {
const data = (await this.lcdService.tendermint.nodeInfo({ height })) as any
const apikey = process.env.API_KEY
const data = (await this.lcdService.tendermint.nodeInfo({ height, 'x-apikey': apikey})) as any

return {
id: data.default_node_info.default_node_id,
Expand Down Expand Up @@ -54,7 +55,8 @@ export class TendermintService {

public async syncing(height?: number): Promise<boolean> {
try {
return this.lcdService.tendermint.syncing({ height })
const apikey = process.env.API_KEY
return this.lcdService.tendermint.syncing({ height, 'x-apikey': apikey })
} catch (err) {
this.logger.error({ err }, 'Error getting the syncing mode.')

Expand All @@ -64,7 +66,8 @@ export class TendermintService {

public async validatorSet(height?: number): Promise<ValidatorSet> {
try {
const [validators] = await this.lcdService.tendermint.validatorSet(height)
const apikey = process.env.API_KEY
const [validators] = await this.lcdService.tendermint.validatorSet(height, {'x-apikey': apikey})

return {
validators: validators.map<DelegateValidator>((validator) => ({
Expand All @@ -83,7 +86,8 @@ export class TendermintService {

public async blockInfo(height?: number): Promise<BlockInfo> {
try {
const info = await this.lcdService.tendermint.blockInfo(height)
const apikey = process.env.API_KEY
const info = await this.lcdService.tendermint.blockInfo(height, {'x-apikey': apikey})

info.block.last_commit.signatures.forEach((s) => {
// terra.js should be fixed to return number
Expand Down
1 change: 1 addition & 0 deletions src/utils/utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class UtilsService {
const { denom, amount } = coin

try {

const tax = await this.lcdService.utils.calculateTax(new TerraCoin(denom, amount))

return Coin.fromTerraCoin(tax)
Expand Down
12 changes: 8 additions & 4 deletions src/wasm/wasm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class WasmService {

public async codeInfo(codeID: number, height?: number): Promise<CodeInfo> {
try {
const info = await this.lcdService.wasm.codeInfo(codeID, { height })
const apikey = process.env.API_KEY
const info = await this.lcdService.wasm.codeInfo(codeID, { height, 'x-apikey': apikey })

return {
code_hash: info.code_hash,
Expand All @@ -31,7 +32,8 @@ export class WasmService {

public async contractInfo(contractAddress: string, height?: number): Promise<ContractInfo> {
try {
const info = await this.lcdService.wasm.contractInfo(contractAddress, { height })
const apikey = process.env.API_KEY
const info = await this.lcdService.wasm.contractInfo(contractAddress, { height, 'x-apikey': apikey })

return {
code_id: info.code_id,
Expand All @@ -49,7 +51,8 @@ export class WasmService {

public async contractQuery(contractAddress: string, query: Record<string, any>, height?: number): Promise<any> {
try {
const data = await this.lcdService.wasm.contractQuery(contractAddress, query, { height })
const apikey = process.env.API_KEY
const data = await this.lcdService.wasm.contractQuery(contractAddress, query, { height, 'x-apikey': apikey })

return data
} catch (err: any) {
Expand All @@ -61,7 +64,8 @@ export class WasmService {

public async parameters(height?: number): Promise<WasmParams> {
try {
const parameters = await this.lcdService.wasm.parameters({ height })
const apikey = process.env.API_KEY
const parameters = await this.lcdService.wasm.parameters({ height, 'x-apikey': apikey })

return parameters
} catch (err) {
Expand Down

0 comments on commit eae0493

Please sign in to comment.