Skip to content

Commit d4cfa51

Browse files
Faizan Dastgirzone117x
authored andcommitted
fix: removed empty status
1 parent 5df254d commit d4cfa51

File tree

8 files changed

+46
-41
lines changed

8 files changed

+46
-41
lines changed

docs/entities/transactions/transaction-status.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"title": "TransactionStatus",
44
"description": "Status of the transaction",
55
"type": "string",
6-
"enum": ["success", "pending", "abort_by_response", "abort_by_post_condition", ""]
6+
"enum": ["success", "pending", "abort_by_response", "abort_by_post_condition"]
77
}

docs/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ export interface CoinbaseTransaction {
20562056
/**
20572057
* Status of the transaction
20582058
*/
2059-
export type TransactionStatus = "success" | "pending" | "abort_by_response" | "abort_by_post_condition" | "";
2059+
export type TransactionStatus = "success" | "pending" | "abort_by_response" | "abort_by_post_condition";
20602060

20612061
/**
20622062
* String literal of all Stacks 2.0 transaction types

rosetta-cli-config/rosetta-config-native.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@
2323
"block_broadcast_limit": 0,
2424
"rebroadcast_all": false,
2525
"constructor_dsl_file": "stacks.ros",
26-
"prefunded_accounts": [
27-
{"privkey": "cb3df38053d132895220b9ce471f6b676db5b9bf0b4adefb55f2118ece2478df",
28-
"account_identifier": {"address": "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6"},
29-
"curve_type": "secp256k1",
30-
"currency": {"symbol": "STX", "decimals": 6}},
31-
{"privkey": "21d43d2ae0da1d9d04cfcaac7d397a33733881081f0b2cd038062cf0ccbb7526",
26+
"prefunded_accounts": [
27+
{"privkey": "21d43d2ae0da1d9d04cfcaac7d397a33733881081f0b2cd038062cf0ccbb7526",
3228
"account_identifier": {"address": "ST11NJTTKGVT6D1HY4NJRVQWMQM7TVAR091EJ8P2Y"},
3329
"curve_type": "secp256k1",
3430
"currency": {"symbol": "STX", "decimals": 6}},

rosetta-cli-config/stacks.ros

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ transfer(10){
7777
{
7878
"operation_identifier":{"index":0},
7979
"type":"fee",
80-
"status" : "pending",
8180
"account":{{sender.account_identifier}},
8281
"amount":{
8382
"value":"-180",
@@ -87,7 +86,6 @@ transfer(10){
8786
{
8887
"operation_identifier":{"index":1},
8988
"type":"token_transfer",
90-
"status" : "pending",
9189
"account":{{sender.account_identifier}},
9290
"amount":{
9391
"value":{{sender_amount}},
@@ -97,7 +95,6 @@ transfer(10){
9795
{
9896
"operation_identifier":{"index":2},
9997
"type":"token_transfer",
100-
"status" : "pending",
10198
"account":{{recipient.account_identifier}},
10299
"amount":{
103100
"value":{{recipient_amount}},

src/api/controllers/db-controller.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
import { readClarityValueArray, readTransactionPostConditions } from '../../p2p/tx';
4747
import { BufferReader } from '../../binary-reader';
4848
import { serializePostCondition, serializePostConditionMode } from '../serializers/post-conditions';
49-
import { DbSmartContractEvent, DbFtEvent, DbNftEvent } from '../../datastore/common';
5049
import { getOperations } from '../../rosetta-helpers';
5150

5251
export function parseTxTypeStrings(values: string[]): TransactionType[] {
@@ -98,7 +97,7 @@ export function getTxTypeId(typeString: Transaction['tx_type']): DbTxTypeId {
9897
}
9998
}
10099

101-
export function getTxStatusString(txStatus: DbTxStatus): Transaction['tx_status'] {
100+
export function getTxStatusString(txStatus: DbTxStatus | string): Transaction['tx_status'] {
102101
switch (txStatus) {
103102
case DbTxStatus.Pending:
104103
return 'pending';
@@ -108,13 +107,22 @@ export function getTxStatusString(txStatus: DbTxStatus): Transaction['tx_status'
108107
return 'abort_by_response';
109108
case DbTxStatus.AbortByPostCondition:
110109
return 'abort_by_post_condition';
111-
case DbTxStatus.Empty:
112-
return '';
110+
case DbTxStatus.AbortByPostCondition:
111+
return 'abort_by_post_condition';
113112
default:
114113
throw new Error(`Unexpected DbTxStatus: ${txStatus}`);
115114
}
116115
}
117116

117+
export function getTxStatus(txStatus: DbTxStatus | string): string {
118+
if(txStatus == ''){
119+
return ''
120+
}else{
121+
return getTxStatusString(txStatus)
122+
}
123+
124+
}
125+
118126
type HasEventTransaction = SmartContractTransaction | ContractCallTransaction;
119127

120128
function getEventTypeString(

src/api/routes/rosetta/construction.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,26 @@ export function createRosettaConstructionRouter(db: DataStore): RouterWithAsync
334334
res.status(400).json(RosettaErrors.invalidParams);
335335
return;
336336
}
337-
const operations = getOperations(rawTxToBaseTx(inputTx));
338-
let response;
339-
if (signed) {
340-
response = {
341-
operations: operations,
342-
account_identifier_signers: getSigners(transaction),
343-
};
344-
} else {
345-
response = {
346-
operations: operations,
347-
};
337+
try {
338+
const operations = getOperations(rawTxToBaseTx(inputTx));
339+
let response;
340+
if (signed) {
341+
response = {
342+
operations: operations,
343+
account_identifier_signers: getSigners(transaction),
344+
};
345+
} else {
346+
response = {
347+
operations: operations,
348+
};
349+
}
350+
res.json(response);
351+
} catch(error) {
352+
console.error(error)
348353
}
349-
res.json(response);
354+
355+
356+
350357
});
351358

352359
//construction/submit endpoint
@@ -530,8 +537,6 @@ export function createRosettaConstructionRouter(db: DataStore): RouterWithAsync
530537
if (!hash.startsWith('01') && hash.slice(128) == '01') {
531538
hash = signatures[0].hex_bytes.slice(128) + signatures[0].hex_bytes.slice(0, -2);
532539
}
533-
// const rotated = signatures[0].hex_bytes.slice(128) + signatures[0].hex_bytes.slice(0, -2);
534-
535540
newSignature = createMessageSignature(hash);
536541
} catch (error) {
537542
res.status(400).json(RosettaErrors.invalidSignature);

src/datastore/common.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ export enum DbTxStatus {
4040
Pending = 0,
4141
Success = 1,
4242
AbortByResponse = -1,
43-
AbortByPostCondition = -2,
44-
Empty = -3,
43+
AbortByPostCondition = -2
4544
}
4645

4746
export interface BaseTx {
@@ -57,7 +56,7 @@ export interface BaseTx {
5756
token_transfer_amount?: bigint;
5857
/** Hex encoded arbitrary message, up to 34 bytes length (should try decoding to an ASCII string). */
5958
token_transfer_memo?: Buffer;
60-
status: DbTxStatus;
59+
status: DbTxStatus | string;
6160
type_id: DbTxTypeId;
6261
/** Only valid for `contract_call` tx types */
6362
contract_call_contract_id?: string;

src/rosetta-helpers.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { ec as EC } from 'elliptic';
3030
import { txidFromData } from '@blockstack/stacks-transactions/lib/utils';
3131
import * as btc from 'bitcoinjs-lib';
3232
import * as c32check from 'c32check';
33-
import { getTxStatusString, getTxTypeString } from './api/controllers/db-controller';
33+
import { getTxTypeString,getTxStatus } from './api/controllers/db-controller';
3434
import { RosettaConstants, RosettaNetworks } from './api/rosetta-constants';
3535
import { BaseTx, DbTxStatus, DbTxTypeId } from './datastore/common';
3636
import { getTxSenderAddress, getTxSponsorAddress } from './event-stream/reader';
@@ -81,7 +81,7 @@ function makeFeeOperation(tx: BaseTx): RosettaOperation {
8181
const fee: RosettaOperation = {
8282
operation_identifier: { index: 0 },
8383
type: 'fee',
84-
status: getTxStatusString(tx.status),
84+
status: getTxStatus(tx.status),
8585
account: { address: tx.sender_address },
8686
amount: {
8787
value: (BigInt(0) - tx.fee_rate).toString(10),
@@ -96,7 +96,7 @@ function makeSenderOperation(tx: BaseTx, index: number): RosettaOperation {
9696
const sender: RosettaOperation = {
9797
operation_identifier: { index: index },
9898
type: getTxTypeString(tx.type_id),
99-
status: getTxStatusString(tx.status),
99+
status: getTxStatus(tx.status),
100100
account: {
101101
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
102102
},
@@ -123,7 +123,7 @@ function makeReceiverOperation(tx: BaseTx, index: number): RosettaOperation {
123123
operation_identifier: { index: index },
124124
related_operations: [{ index: 0, operation_identifier: { index: 1 } }],
125125
type: getTxTypeString(tx.type_id),
126-
status: getTxStatusString(tx.status),
126+
status: getTxStatus(tx.status),
127127
account: {
128128
address: unwrapOptional(
129129
tx.token_transfer_recipient_address,
@@ -150,7 +150,7 @@ function makeDeployContractOperation(tx: BaseTx, index: number): RosettaOperatio
150150
const deployer: RosettaOperation = {
151151
operation_identifier: { index: index },
152152
type: getTxTypeString(tx.type_id),
153-
status: getTxStatusString(tx.status),
153+
status: getTxStatus(tx.status),
154154
account: {
155155
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
156156
},
@@ -163,7 +163,7 @@ function makeCallContractOperation(tx: BaseTx, index: number): RosettaOperation
163163
const caller: RosettaOperation = {
164164
operation_identifier: { index: index },
165165
type: getTxTypeString(tx.type_id),
166-
status: getTxStatusString(tx.status),
166+
status: getTxStatus(tx.status),
167167
account: {
168168
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
169169
sub_account: {
@@ -186,7 +186,7 @@ function makeCoinbaseOperation(tx: BaseTx, index: number): RosettaOperation {
186186
const sender: RosettaOperation = {
187187
operation_identifier: { index: index },
188188
type: getTxTypeString(tx.type_id),
189-
status: getTxStatusString(tx.status),
189+
status: getTxStatus(tx.status),
190190
account: {
191191
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
192192
},
@@ -200,7 +200,7 @@ function makePoisonMicroblockOperation(tx: BaseTx, index: number): RosettaOperat
200200
const sender: RosettaOperation = {
201201
operation_identifier: { index: index },
202202
type: getTxTypeString(tx.type_id),
203-
status: getTxStatusString(tx.status),
203+
status: getTxStatus(tx.status),
204204
account: {
205205
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
206206
},
@@ -359,7 +359,7 @@ export function rawTxToBaseTx(raw_tx: string): BaseTx {
359359
token_transfer_recipient_address: recipientAddr,
360360
tx_id: txId,
361361
type_id: transactionType,
362-
status: DbTxStatus.Empty,
362+
status: '',
363363
fee_rate: fee,
364364
sender_address: txSender,
365365
token_transfer_amount: amount,

0 commit comments

Comments
 (0)