Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution: return tx index in block #37

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emeraldpay/api",
"version": "0.4.3",
"version": "0.4.4-dev",
"description": "Common code for Emerald gRPC APIs",
"license": "Apache-2.0",
"main": "lib/index.js",
Expand Down
54 changes: 28 additions & 26 deletions packages/core/src/typesTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import * as transaction_message_pb from './generated/transaction.message_pb';
import { DataMapper } from './Publisher';
import {
AnyAddress,
BlockInfo,
Blockchain,
ConvertCommon,
SingleAddress,
} from './typesCommon';
import { AnyAddress, BlockInfo, Blockchain, ConvertCommon, SingleAddress } from './typesCommon';
import { MessageFactory } from './typesConvert';

export enum Direction {
Expand Down Expand Up @@ -47,9 +41,10 @@ export interface AddressTransaction {
cursor?: string;
/** True if transaction is removed from blockchain */
removed: boolean;
/** True if transaction is failed */
/** True if the transaction is failed */
failed: boolean;
changes: Change[];
txIndexInBlock?: number;
}

export interface AddressAmount {
Expand Down Expand Up @@ -82,20 +77,31 @@ export class ConvertTransaction {
}

public getTransactionsRequest(req: GetTransactionsRequest): transaction_message_pb.GetTransactionsRequest {
const result: transaction_message_pb.GetTransactionsRequest = this.factory('transaction_message_pb.GetTransactionsRequest');
return result
.setChain(req.blockchain.valueOf())
const result: transaction_message_pb.GetTransactionsRequest = this.factory(
'transaction_message_pb.GetTransactionsRequest',
);

result
.setAddress(this.common.pbAnyAddress(req.address))
.setCursor(req.cursor)
.setChain(req.blockchain.valueOf())
.setLimit(req.limit)
.setUnspentOnly(req.onlyUnspent);

if (req.cursor != null) {
result.setCursor(req.cursor);
}

return result;
}

public subscribeTransactionsRequest(req: SubscribeTransactionsRequest): transaction_message_pb.SubscribeTransactionsRequest {
const result: transaction_message_pb.SubscribeTransactionsRequest = this.factory('transaction_message_pb.SubscribeTransactionsRequest');
return result
.setChain(req.blockchain.valueOf())
.setAddress(this.common.pbAnyAddress(req.address))
public subscribeTransactionsRequest(
req: SubscribeTransactionsRequest,
): transaction_message_pb.SubscribeTransactionsRequest {
const result: transaction_message_pb.SubscribeTransactionsRequest = this.factory(
'transaction_message_pb.SubscribeTransactionsRequest',
);

return result.setChain(req.blockchain.valueOf()).setAddress(this.common.pbAnyAddress(req.address));
}

private static change(change: transaction_message_pb.Change): Change {
Expand All @@ -117,25 +123,21 @@ export class ConvertTransaction {
block = this.common.blockInfo(resp.getBlock());
}

const blockchain = resp.getChain().valueOf();
const changes = resp.getChangesList().map((value) => ConvertTransaction.change(value));
const cursor = resp.getCursor();
const mempool = resp.getMempool();
const xpubIndex = resp.hasXpubIndex() ? resp.getXpubIndex().getValue() : undefined;

return {
block,
blockchain,
changes,
mempool,
xpubIndex,
address: resp.getAddress().getAddress(),
blockchain: resp.getChain().valueOf(),
changes: resp.getChangesList().map((value) => ConvertTransaction.change(value)),
cursor: cursor.length > 0 ? cursor : undefined,
failed: resp.getFailed(),
mempool: resp.getMempool(),
removed: resp.getRemoved(),
txId: resp.getTxId(),
txIndexInBlock: block == null ? undefined : resp.getTxIndexInBlock(),
xpubIndex: resp.hasXpubIndex() ? resp.getXpubIndex().getValue() : undefined,
};
};
}

}
4 changes: 2 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emeraldpay/api-node",
"version": "0.4.3",
"version": "0.4.4-dev",
"description": "Node client for Emerald gRPC APIs",
"license": "Apache-2.0",
"main": "lib/index.js",
Expand Down Expand Up @@ -32,7 +32,7 @@
"test": "jest"
},
"dependencies": {
"@emeraldpay/api": "0.4.3",
"@emeraldpay/api": "0.4.4-dev",
"@grpc/grpc-js": "^1.9.0",
"google-protobuf": "^3.21.2",
"protobufjs": "^7.2.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emeraldpay/api-web",
"version": "0.4.3",
"version": "0.4.4-dev",
"description": "Browser client for Emerald gRPC APIs",
"license": "Apache-2.0",
"main": "lib/index.js",
Expand Down Expand Up @@ -31,7 +31,7 @@
"test": "jest"
},
"dependencies": {
"@emeraldpay/api": "0.4.3",
"@emeraldpay/api": "0.4.4-dev",
"google-protobuf": "^3.21.2",
"grpc-web": "^1.4.2",
"protobufjs": "^7.2.4"
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@emeraldpay/api-node@workspace:packages/node"
dependencies:
"@emeraldpay/api": 0.4.3
"@emeraldpay/api": 0.4.4-dev
"@grpc/grpc-js": ^1.9.0
"@grpc/proto-loader": ^0.7.8
"@types/google-protobuf": ^3.15.6
Expand All @@ -502,7 +502,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@emeraldpay/api-web@workspace:packages/web"
dependencies:
"@emeraldpay/api": 0.4.3
"@emeraldpay/api": 0.4.4-dev
"@types/google-protobuf": ^3.15.6
"@types/jest": ^29.5.3
google-protobuf: ^3.21.2
Expand All @@ -520,7 +520,7 @@ __metadata:
languageName: unknown
linkType: soft

"@emeraldpay/api@0.4.3, @emeraldpay/api@workspace:packages/core":
"@emeraldpay/api@0.4.4-dev, @emeraldpay/api@workspace:packages/core":
version: 0.0.0-use.local
resolution: "@emeraldpay/api@workspace:packages/core"
dependencies:
Expand Down