Skip to content

Commit c035e8e

Browse files
authored
Merge pull request #227 from starius/get-transaction
walletkit: add RPC GetTransaction
2 parents 0e5a2b0 + 0bb2748 commit c035e8e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

testdata/permissions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,14 @@
11361136
}
11371137
]
11381138
},
1139+
"/walletrpc.WalletKit/GetTransaction": {
1140+
"permissions": [
1141+
{
1142+
"entity": "onchain",
1143+
"action": "read"
1144+
}
1145+
]
1146+
},
11391147
"/walletrpc.WalletKit/PendingSweeps": {
11401148
"permissions": [
11411149
{

walletkit_client.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ type WalletKitClient interface {
101101
addressType walletrpc.AddressType,
102102
change bool) (btcutil.Address, error)
103103

104+
// GetTransaction returns details for a transaction found in the wallet.
105+
GetTransaction(ctx context.Context,
106+
txid chainhash.Hash) (Transaction, error)
107+
104108
PublishTransaction(ctx context.Context, tx *wire.MsgTx,
105109
label string) error
106110

@@ -481,6 +485,26 @@ func (m *walletKitClient) NextAddr(ctx context.Context, accountName string,
481485
return addr, nil
482486
}
483487

488+
// GetTransaction returns details for a transaction found in the wallet.
489+
func (m *walletKitClient) GetTransaction(ctx context.Context,
490+
txid chainhash.Hash) (Transaction, error) {
491+
492+
rpcCtx, cancel := context.WithTimeout(ctx, m.timeout)
493+
defer cancel()
494+
495+
rpcCtx = m.walletKitMac.WithMacaroonAuth(rpcCtx)
496+
497+
req := &walletrpc.GetTransactionRequest{
498+
Txid: txid.String(),
499+
}
500+
resp, err := m.client.GetTransaction(rpcCtx, req)
501+
if err != nil {
502+
return Transaction{}, err
503+
}
504+
505+
return unmarshallTransaction(resp)
506+
}
507+
484508
func (m *walletKitClient) PublishTransaction(ctx context.Context,
485509
tx *wire.MsgTx, label string) error {
486510

0 commit comments

Comments
 (0)