Skip to content

Commit

Permalink
Merge pull request #36 from Microflow-xyz/feature/poll
Browse files Browse the repository at this point in the history
poll added to controller
  • Loading branch information
ahmadyazdanii authored Jun 27, 2024
2 parents 60c8f4e + aed0771 commit 2092f60
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/chains/ergo/ergo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import {
AssetsResponse,
BalanceRequest,
PollRequest,
PollResponse,
PoolRequest,
PoolResponse,
TransferRequest,
Expand All @@ -22,7 +24,13 @@ export class ErgoController {

return ergo.getPool(req.poolId).info;
}
static async poll(ergo: Ergo, req: PollRequest): Promise<PollResponse> {
if (!ergo.ready) {
await ergo.init();
}

return await ergo.getTx(req.txId);
}
static async balances(chain: Ergo, request: BalanceRequest) {
if (!chain.ready) {
await chain.init();
Expand Down
4 changes: 4 additions & 0 deletions src/chains/ergo/ergo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,8 @@ export class Ergo {
public getPool(id: string): Pool {
return <Pool>this.ammPools.find((ammPool) => ammPool.id === id);
}

public async getTx(id: string): Promise<ErgoTx> {
return await this._node.getTxsById(id);
}
}
7 changes: 6 additions & 1 deletion src/chains/ergo/interfaces/requests.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AssetAmount } from '@patternglobal/ergo-sdk';
import { AssetAmount, ErgoTx } from '@patternglobal/ergo-sdk';
import { NetworkSelectionRequest } from '../../../services/common-interfaces';
import { ErgoAsset, ErgoBoxAsset } from './ergo.interface';

Expand All @@ -16,6 +16,11 @@ export interface PoolResponse {
feeDenom: bigint;
}

export interface PollResponse extends ErgoTx {}
export interface PollRequest {
txId: string;
}

export interface BalanceRequest extends NetworkSelectionRequest {
address: string; // the users public key
}
Expand Down
4 changes: 4 additions & 0 deletions src/chains/ergo/node.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ErgoStateContext,
PreHeader,
} from 'ergo-lib-wasm-nodejs';
import { ErgoTx } from '@patternglobal/ergo-sdk';

/**
* This class allows you to access elements of a node
Expand Down Expand Up @@ -102,4 +103,7 @@ export class NodeService {
tx,
);
}
async getTxsById(id: string): Promise<ErgoTx> {
return this.request<ErgoTx>('GET', `/blockchain/transaction/byId/${id}`);
}
}

0 comments on commit 2092f60

Please sign in to comment.