Skip to content

Commit

Permalink
Connect to getGatewayTransaction endpoint (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsidorenko authored Jul 13, 2021
1 parent c9a032b commit 847d93a
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "etherspot",
"version": "1.12.0",
"version": "1.13.0",
"description": "Etherspot SDK",
"keywords": [
"ether",
Expand Down
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ type GatewaySupportedTokens {
}

type GatewayTransaction {
batches: [GatewayBatch!]!
createdAt: DateTime!
gasPrice: BigNumber!
gasUsed: Int
Expand Down Expand Up @@ -461,6 +462,7 @@ type Query {
gatewaySenders(chainId: Int): GatewaySenders!
gatewaySupportedToken(chainId: Int, token: String!): GatewaySupportedToken
gatewaySupportedTokens(chainId: Int): GatewaySupportedTokens!
gatewayTransaction(chainId: Int, hash: String!): GatewayTransaction
getContractAbi(address: String!, chainId: Int): JSONObject
isTokenOnTokenList(chainId: Int, name: String, token: String!): Boolean!
nativeCurrencies: NativeCurrencies!
Expand Down
4 changes: 4 additions & 0 deletions src/sdk/gateway/classes/gateway-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { Type } from 'class-transformer';
import { BigNumber } from 'ethers';
import { TransformBigNumber } from '../../common';
import { GatewayTransactionStates } from '../constants';
import { GatewaySubmittedBatch } from './gateway-submitted-batch';

export class GatewayTransaction {
hash: string;

@Type(() => GatewaySubmittedBatch)
batches: Array<Partial<GatewaySubmittedBatch>>;

state: GatewayTransactionStates;

sender: string;
Expand Down
64 changes: 64 additions & 0 deletions src/sdk/gateway/gateway.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GatewaySubmittedBatches,
GatewaySupportedToken,
GatewaySupportedTokens,
GatewayTransaction,
} from './classes';
import { GatewayKnownOps } from './constants';
import { GatewayBatch } from './interfaces';
Expand Down Expand Up @@ -274,6 +275,69 @@ export class GatewayService extends Service {
return result;
}

async getGatewayTransaction(hash: string): Promise<GatewayTransaction> {
const { apiService, contractService } = this.services;

const { result } = await apiService.query<{
result: GatewayTransaction;
}>(
gql`
query($chainId: Int, $hash: String!) {
result: gatewayTransaction(chainId: $chainId, hash: $hash) {
hash
state
sender
gasPrice
gasUsed
totalCost
createdAt
updatedAt
batches {
logs {
address
data
topics
}
hash
state
account
nonce
to
data
senderSignature
estimatedGas
estimatedGasPrice
feeToken
feeAmount
feeData
createdAt
updatedAt
}
}
}
`,
{
models: {
result: GatewayTransaction,
},
variables: {
hash,
},
},
);

if (result && result.batches && Array.isArray(result.batches)) {
result.batches = result.batches.map((batch) => {
if (batch.logs) {
batch.events = contractService.processContractsLogs(batch.logs);
}
return batch;
});
}

return result;
}

async getGatewayGasInfo(): Promise<GatewayGasInfo> {
const { apiService } = this.services;

Expand Down
14 changes: 14 additions & 0 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
GetENSRootNodeDto,
GetExchangeOffersDto,
GetGatewaySubmittedBatchDto,
GetGatewaySubmittedBatchDto as GetGatewayTransactionDto,
GetGatewaySupportedTokenDto,
GetP2PPaymentChannelDto,
GetP2PPaymentChannelsDto,
Expand Down Expand Up @@ -100,6 +101,7 @@ import {
GatewaySubmittedBatches,
GatewaySubmittedPendingBatches,
GatewaySupportedToken,
GatewayTransaction,
} from './gateway';
import { SdkOptions } from './interfaces';
import { Network, NetworkNames, NetworkService } from './network';
Expand Down Expand Up @@ -346,6 +348,18 @@ export class Sdk {

return this.services.gatewayService.getGatewaySubmittedPendingBatches(page || 1);
}

/**
* gets gateway transaction details
* @param dto
* @return Promise<GatewayTransaction>
*/
async getGatewayTransaction(dto: GetGatewayTransactionDto): Promise<GatewayTransaction> {
const { hash } = await validateDto(dto, GetGatewayTransactionDto);

return this.services.gatewayService.getGatewayTransaction(hash);
}

/**
* gets gateway's gas info
* @return Promise<GatewayGasInfo>
Expand Down

0 comments on commit 847d93a

Please sign in to comment.