Skip to content

Commit

Permalink
adds missing fields to wallet transaction RPCs (#3768)
Browse files Browse the repository at this point in the history
adds transaction fields needed for developers to determine transaction status
independently of the node

- adds blockHash and blockSequence to wallet/getAccountTransactions
- adds submittedSequence to responses for both wallet/getAccountTransaction and
  wallet/getAccountTransactions
- adds confirmations to wallet/getAccountTransaction and
  wallet/getAccountTransactions
  • Loading branch information
hughy authored Apr 10, 2023
1 parent ff39037 commit e24ca41
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
29 changes: 18 additions & 11 deletions ironfish/src/rpc/routes/wallet/getTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type GetAccountTransactionResponse = {
transaction: {
hash: string
status: TransactionStatus
confirmations: number
type: TransactionType
fee: string
blockHash?: string
Expand All @@ -32,8 +33,9 @@ export type GetAccountTransactionResponse = {
mintsCount: number
burnsCount: number
timestamp: number
notes: RpcAccountDecryptedNote[]
submittedSequence: number
assetBalanceDeltas: Array<{ assetId: string; assetName: string; delta: string }>
notes: RpcAccountDecryptedNote[]
} | null
}

Expand All @@ -54,6 +56,7 @@ export const GetAccountTransactionResponseSchema: yup.ObjectSchema<GetAccountTra
.object({
hash: yup.string().required(),
status: yup.string().oneOf(Object.values(TransactionStatus)).defined(),
confirmations: yup.number().defined(),
type: yup.string().oneOf(Object.values(TransactionType)).defined(),
fee: yup.string().defined(),
blockHash: yup.string().optional(),
Expand All @@ -63,29 +66,30 @@ export const GetAccountTransactionResponseSchema: yup.ObjectSchema<GetAccountTra
mintsCount: yup.number().defined(),
burnsCount: yup.number().defined(),
timestamp: yup.number().defined(),
notes: yup
submittedSequence: yup.number().defined(),
assetBalanceDeltas: yup
.array(
yup
.object({
isOwner: yup.boolean().defined(),
owner: yup.string().defined(),
value: yup.string().defined(),
assetId: yup.string().defined(),
assetName: yup.string().defined(),
sender: yup.string().defined(),
memo: yup.string().trim().defined(),
spent: yup.boolean(),
delta: yup.string().defined(),
})
.defined(),
)
.defined(),
assetBalanceDeltas: yup
notes: yup
.array(
yup
.object({
isOwner: yup.boolean().defined(),
owner: yup.string().defined(),
value: yup.string().defined(),
assetId: yup.string().defined(),
assetName: yup.string().defined(),
delta: yup.string().defined(),
sender: yup.string().defined(),
memo: yup.string().trim().defined(),
spent: yup.boolean(),
})
.defined(),
)
Expand Down Expand Up @@ -118,8 +122,10 @@ router.register<typeof GetAccountTransactionRequestSchema, GetAccountTransaction

const notes = await getAccountDecryptedNotes(node, account, transaction)

const confirmations = request.data.confirmations ?? node.config.get('confirmations')

const status = await node.wallet.getTransactionStatus(account, transaction, {
confirmations: request.data.confirmations,
confirmations,
})

const type = await node.wallet.getTransactionType(account, transaction)
Expand All @@ -130,6 +136,7 @@ router.register<typeof GetAccountTransactionRequestSchema, GetAccountTransaction
notes,
status,
type,
confirmations,
}

request.end({
Expand Down
21 changes: 15 additions & 6 deletions ironfish/src/rpc/routes/wallet/getTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ export type GetAccountTransactionsRequest = {
}

export type GetAccountTransactionsResponse = {
hash: string
status: TransactionStatus
type: TransactionType
hash: string
confirmations: number
fee: string
blockHash?: string
blockSequence?: number
notesCount: number
spendsCount: number
mintsCount: number
burnsCount: number
expiration: number
timestamp: number
submittedSequence: number
assetBalanceDeltas: Array<{ assetId: string; assetName: string; delta: string }>
notes?: RpcAccountDecryptedNote[]
}
Expand All @@ -58,16 +62,20 @@ export const GetAccountTransactionsRequestSchema: yup.ObjectSchema<GetAccountTra
export const GetAccountTransactionsResponseSchema: yup.ObjectSchema<GetAccountTransactionsResponse> =
yup
.object({
hash: yup.string().defined(),
status: yup.string().oneOf(Object.values(TransactionStatus)).defined(),
confirmations: yup.number().defined(),
type: yup.string().oneOf(Object.values(TransactionType)).defined(),
hash: yup.string().defined(),
fee: yup.string().defined(),
blockHash: yup.string().optional(),
blockSequence: yup.number().optional(),
notesCount: yup.number().defined(),
spendsCount: yup.number().defined(),
mintsCount: yup.number().defined(),
burnsCount: yup.number().defined(),
expiration: yup.number().defined(),
timestamp: yup.number().defined(),
submittedSequence: yup.number().defined(),
assetBalanceDeltas: yup
.array(
yup
Expand Down Expand Up @@ -106,7 +114,7 @@ router.register<typeof GetAccountTransactionsRequestSchema, GetAccountTransactio

const options = {
headSequence,
confirmations: request.data.confirmations,
confirmations: request.data.confirmations ?? node.config.get('confirmations'),
}

if (request.data.hash) {
Expand Down Expand Up @@ -155,9 +163,9 @@ const streamTransaction = async (
node: IronfishNode,
account: Account,
transaction: TransactionValue,
options?: {
headSequence?: number | null
confirmations?: number
options: {
headSequence: number | null
confirmations: number
},
): Promise<void> => {
const serializedTransaction = serializeRpcAccountTransaction(transaction)
Expand All @@ -176,6 +184,7 @@ const streamTransaction = async (
...serializedTransaction,
assetBalanceDeltas,
status,
confirmations: options.confirmations,
type,
notes,
}
Expand Down

0 comments on commit e24ca41

Please sign in to comment.