Skip to content

Commit

Permalink
fix: removed empty status
Browse files Browse the repository at this point in the history
  • Loading branch information
fdmirza authored and zone117x committed Nov 5, 2020
1 parent 5df254d commit d4cfa51
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 41 deletions.
2 changes: 1 addition & 1 deletion docs/entities/transactions/transaction-status.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"title": "TransactionStatus",
"description": "Status of the transaction",
"type": "string",
"enum": ["success", "pending", "abort_by_response", "abort_by_post_condition", ""]
"enum": ["success", "pending", "abort_by_response", "abort_by_post_condition"]
}
2 changes: 1 addition & 1 deletion docs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2056,7 +2056,7 @@ export interface CoinbaseTransaction {
/**
* Status of the transaction
*/
export type TransactionStatus = "success" | "pending" | "abort_by_response" | "abort_by_post_condition" | "";
export type TransactionStatus = "success" | "pending" | "abort_by_response" | "abort_by_post_condition";

/**
* String literal of all Stacks 2.0 transaction types
Expand Down
8 changes: 2 additions & 6 deletions rosetta-cli-config/rosetta-config-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
"block_broadcast_limit": 0,
"rebroadcast_all": false,
"constructor_dsl_file": "stacks.ros",
"prefunded_accounts": [
{"privkey": "cb3df38053d132895220b9ce471f6b676db5b9bf0b4adefb55f2118ece2478df",
"account_identifier": {"address": "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6"},
"curve_type": "secp256k1",
"currency": {"symbol": "STX", "decimals": 6}},
{"privkey": "21d43d2ae0da1d9d04cfcaac7d397a33733881081f0b2cd038062cf0ccbb7526",
"prefunded_accounts": [
{"privkey": "21d43d2ae0da1d9d04cfcaac7d397a33733881081f0b2cd038062cf0ccbb7526",
"account_identifier": {"address": "ST11NJTTKGVT6D1HY4NJRVQWMQM7TVAR091EJ8P2Y"},
"curve_type": "secp256k1",
"currency": {"symbol": "STX", "decimals": 6}},
Expand Down
3 changes: 0 additions & 3 deletions rosetta-cli-config/stacks.ros
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ transfer(10){
{
"operation_identifier":{"index":0},
"type":"fee",
"status" : "pending",
"account":{{sender.account_identifier}},
"amount":{
"value":"-180",
Expand All @@ -87,7 +86,6 @@ transfer(10){
{
"operation_identifier":{"index":1},
"type":"token_transfer",
"status" : "pending",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
Expand All @@ -97,7 +95,6 @@ transfer(10){
{
"operation_identifier":{"index":2},
"type":"token_transfer",
"status" : "pending",
"account":{{recipient.account_identifier}},
"amount":{
"value":{{recipient_amount}},
Expand Down
16 changes: 12 additions & 4 deletions src/api/controllers/db-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import {
import { readClarityValueArray, readTransactionPostConditions } from '../../p2p/tx';
import { BufferReader } from '../../binary-reader';
import { serializePostCondition, serializePostConditionMode } from '../serializers/post-conditions';
import { DbSmartContractEvent, DbFtEvent, DbNftEvent } from '../../datastore/common';
import { getOperations } from '../../rosetta-helpers';

export function parseTxTypeStrings(values: string[]): TransactionType[] {
Expand Down Expand Up @@ -98,7 +97,7 @@ export function getTxTypeId(typeString: Transaction['tx_type']): DbTxTypeId {
}
}

export function getTxStatusString(txStatus: DbTxStatus): Transaction['tx_status'] {
export function getTxStatusString(txStatus: DbTxStatus | string): Transaction['tx_status'] {
switch (txStatus) {
case DbTxStatus.Pending:
return 'pending';
Expand All @@ -108,13 +107,22 @@ export function getTxStatusString(txStatus: DbTxStatus): Transaction['tx_status'
return 'abort_by_response';
case DbTxStatus.AbortByPostCondition:
return 'abort_by_post_condition';
case DbTxStatus.Empty:
return '';
case DbTxStatus.AbortByPostCondition:
return 'abort_by_post_condition';
default:
throw new Error(`Unexpected DbTxStatus: ${txStatus}`);
}
}

export function getTxStatus(txStatus: DbTxStatus | string): string {
if(txStatus == ''){
return ''
}else{
return getTxStatusString(txStatus)
}

}

type HasEventTransaction = SmartContractTransaction | ContractCallTransaction;

function getEventTypeString(
Expand Down
33 changes: 19 additions & 14 deletions src/api/routes/rosetta/construction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,26 @@ export function createRosettaConstructionRouter(db: DataStore): RouterWithAsync
res.status(400).json(RosettaErrors.invalidParams);
return;
}
const operations = getOperations(rawTxToBaseTx(inputTx));
let response;
if (signed) {
response = {
operations: operations,
account_identifier_signers: getSigners(transaction),
};
} else {
response = {
operations: operations,
};
try {
const operations = getOperations(rawTxToBaseTx(inputTx));
let response;
if (signed) {
response = {
operations: operations,
account_identifier_signers: getSigners(transaction),
};
} else {
response = {
operations: operations,
};
}
res.json(response);
} catch(error) {
console.error(error)
}
res.json(response);



});

//construction/submit endpoint
Expand Down Expand Up @@ -530,8 +537,6 @@ export function createRosettaConstructionRouter(db: DataStore): RouterWithAsync
if (!hash.startsWith('01') && hash.slice(128) == '01') {
hash = signatures[0].hex_bytes.slice(128) + signatures[0].hex_bytes.slice(0, -2);
}
// const rotated = signatures[0].hex_bytes.slice(128) + signatures[0].hex_bytes.slice(0, -2);

newSignature = createMessageSignature(hash);
} catch (error) {
res.status(400).json(RosettaErrors.invalidSignature);
Expand Down
5 changes: 2 additions & 3 deletions src/datastore/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export enum DbTxStatus {
Pending = 0,
Success = 1,
AbortByResponse = -1,
AbortByPostCondition = -2,
Empty = -3,
AbortByPostCondition = -2
}

export interface BaseTx {
Expand All @@ -57,7 +56,7 @@ export interface BaseTx {
token_transfer_amount?: bigint;
/** Hex encoded arbitrary message, up to 34 bytes length (should try decoding to an ASCII string). */
token_transfer_memo?: Buffer;
status: DbTxStatus;
status: DbTxStatus | string;
type_id: DbTxTypeId;
/** Only valid for `contract_call` tx types */
contract_call_contract_id?: string;
Expand Down
18 changes: 9 additions & 9 deletions src/rosetta-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ec as EC } from 'elliptic';
import { txidFromData } from '@blockstack/stacks-transactions/lib/utils';
import * as btc from 'bitcoinjs-lib';
import * as c32check from 'c32check';
import { getTxStatusString, getTxTypeString } from './api/controllers/db-controller';
import { getTxTypeString,getTxStatus } from './api/controllers/db-controller';
import { RosettaConstants, RosettaNetworks } from './api/rosetta-constants';
import { BaseTx, DbTxStatus, DbTxTypeId } from './datastore/common';
import { getTxSenderAddress, getTxSponsorAddress } from './event-stream/reader';
Expand Down Expand Up @@ -81,7 +81,7 @@ function makeFeeOperation(tx: BaseTx): RosettaOperation {
const fee: RosettaOperation = {
operation_identifier: { index: 0 },
type: 'fee',
status: getTxStatusString(tx.status),
status: getTxStatus(tx.status),
account: { address: tx.sender_address },
amount: {
value: (BigInt(0) - tx.fee_rate).toString(10),
Expand All @@ -96,7 +96,7 @@ function makeSenderOperation(tx: BaseTx, index: number): RosettaOperation {
const sender: RosettaOperation = {
operation_identifier: { index: index },
type: getTxTypeString(tx.type_id),
status: getTxStatusString(tx.status),
status: getTxStatus(tx.status),
account: {
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
},
Expand All @@ -123,7 +123,7 @@ function makeReceiverOperation(tx: BaseTx, index: number): RosettaOperation {
operation_identifier: { index: index },
related_operations: [{ index: 0, operation_identifier: { index: 1 } }],
type: getTxTypeString(tx.type_id),
status: getTxStatusString(tx.status),
status: getTxStatus(tx.status),
account: {
address: unwrapOptional(
tx.token_transfer_recipient_address,
Expand All @@ -150,7 +150,7 @@ function makeDeployContractOperation(tx: BaseTx, index: number): RosettaOperatio
const deployer: RosettaOperation = {
operation_identifier: { index: index },
type: getTxTypeString(tx.type_id),
status: getTxStatusString(tx.status),
status: getTxStatus(tx.status),
account: {
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
},
Expand All @@ -163,7 +163,7 @@ function makeCallContractOperation(tx: BaseTx, index: number): RosettaOperation
const caller: RosettaOperation = {
operation_identifier: { index: index },
type: getTxTypeString(tx.type_id),
status: getTxStatusString(tx.status),
status: getTxStatus(tx.status),
account: {
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
sub_account: {
Expand All @@ -186,7 +186,7 @@ function makeCoinbaseOperation(tx: BaseTx, index: number): RosettaOperation {
const sender: RosettaOperation = {
operation_identifier: { index: index },
type: getTxTypeString(tx.type_id),
status: getTxStatusString(tx.status),
status: getTxStatus(tx.status),
account: {
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
},
Expand All @@ -200,7 +200,7 @@ function makePoisonMicroblockOperation(tx: BaseTx, index: number): RosettaOperat
const sender: RosettaOperation = {
operation_identifier: { index: index },
type: getTxTypeString(tx.type_id),
status: getTxStatusString(tx.status),
status: getTxStatus(tx.status),
account: {
address: unwrapOptional(tx.sender_address, () => 'Unexpected nullish sender_address'),
},
Expand Down Expand Up @@ -359,7 +359,7 @@ export function rawTxToBaseTx(raw_tx: string): BaseTx {
token_transfer_recipient_address: recipientAddr,
tx_id: txId,
type_id: transactionType,
status: DbTxStatus.Empty,
status: '',
fee_rate: fee,
sender_address: txSender,
token_transfer_amount: amount,
Expand Down

0 comments on commit d4cfa51

Please sign in to comment.