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

adds missing fields to wallet transaction RPCs #3768

Merged
merged 1 commit into from
Apr 10, 2023
Merged
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
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTransactonStatus already materializes this so I dont think we need this code in the RPC do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm materializing it here only to include it in the response


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'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to materialize this here right? it gets materialized where its used farther down

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above -- we only need to materialize this here to include it in the response

}

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