Skip to content

Commit

Permalink
Improve RPC client types for broadcastTransaction and isValidPublicAd…
Browse files Browse the repository at this point in the history
…dress (#5356)

Also logs if the transaction is not accepted or broadcast when calling the CLI chain:broadcast command.
  • Loading branch information
dguenther authored Sep 4, 2024
1 parent 8a949b3 commit 3e3b650
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion ironfish-cli/src/commands/chain/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ export class BroadcastCommand extends IronfishCommand {
ux.action.start(`Broadcasting transaction`)
const client = await this.connectRpc()
const response = await client.chain.broadcastTransaction({ transaction })
if (response.content) {

if (response.content.accepted && response.content.broadcasted) {
ux.action.stop(`Transaction broadcasted: ${response.content.hash}`)
} else {
ux.action.stop()
this.error(
`Transaction broadcast may have failed.${
!response.content.accepted ? ' Transaction was not accepted by the node.' : ''
}${
!response.content.broadcasted
? ' Transaction was not broadcasted to the network.'
: ''
}`,
)
}
}
}
4 changes: 2 additions & 2 deletions ironfish/src/rpc/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ export abstract class RpcClient {

isValidPublicAddress: (
params: IsValidPublicAddressRequest,
): Promise<RpcResponse<IsValidPublicAddressResponse>> => {
): Promise<RpcResponseEnded<IsValidPublicAddressResponse>> => {
return this.request<IsValidPublicAddressResponse>(
`${ApiNamespace.chain}/isValidPublicAddress`,
params,
Expand All @@ -1022,7 +1022,7 @@ export abstract class RpcClient {

broadcastTransaction: (
params: BroadcastTransactionRequest,
): Promise<RpcResponse<BroadcastTransactionResponse>> => {
): Promise<RpcResponseEnded<BroadcastTransactionResponse>> => {
return this.request<BroadcastTransactionResponse>(
`${ApiNamespace.chain}/broadcastTransaction`,
params,
Expand Down

0 comments on commit 3e3b650

Please sign in to comment.