Convert NewTxNtfn to use new concrete type.
The NewTxNtfn notification was previously using a map[string]interface. This commit modifies it to use the new concrete type btcjson.ListTransactionsResult instead which allows nicer marshalling and unmarshalling. ok @jrick
This commit is contained in:
parent
fc07555ad3
commit
fdc49d6a30
2 changed files with 38 additions and 15 deletions
|
@ -786,14 +786,14 @@ func (n *RescanProgressNtfn) UnmarshalJSON(b []byte) error {
|
|||
// unmarshaling of newtx JSON websocket notifications.
|
||||
type TxNtfn struct {
|
||||
Account string
|
||||
Details map[string]interface{}
|
||||
Details *btcjson.ListTransactionsResult
|
||||
}
|
||||
|
||||
// Enforce that TxNtfn satisifies the btcjson.Cmd interface.
|
||||
var _ btcjson.Cmd = &TxNtfn{}
|
||||
|
||||
// NewTxNtfn creates a new TxNtfn.
|
||||
func NewTxNtfn(account string, details map[string]interface{}) *TxNtfn {
|
||||
func NewTxNtfn(account string, details *btcjson.ListTransactionsResult) *TxNtfn {
|
||||
return &TxNtfn{
|
||||
Account: account,
|
||||
Details: details,
|
||||
|
@ -818,14 +818,13 @@ func parseTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) {
|
|||
"string: " + err.Error())
|
||||
}
|
||||
|
||||
// TODO(davec): Object
|
||||
var details map[string]interface{}
|
||||
var details btcjson.ListTransactionsResult
|
||||
if err := json.Unmarshal(r.Params[1], &details); err != nil {
|
||||
return nil, errors.New("second parameter 'details' must be a " +
|
||||
"JSON object of transaction details: " + err.Error())
|
||||
}
|
||||
|
||||
return NewTxNtfn(account, details), nil
|
||||
return NewTxNtfn(account, &details), nil
|
||||
}
|
||||
|
||||
// Id satisifies the btcjson.Cmd interface by returning nil for a
|
||||
|
|
|
@ -135,21 +135,45 @@ var ntfntests = []struct {
|
|||
{
|
||||
name: "newtx",
|
||||
f: func() btcjson.Cmd {
|
||||
details := map[string]interface{}{
|
||||
"key1": float64(12345),
|
||||
"key2": true,
|
||||
"key3": "lalala",
|
||||
"key4": []interface{}{"abcde", float64(12345)},
|
||||
details := &btcjson.ListTransactionsResult{
|
||||
Account: "original",
|
||||
Address: "mnSsMBY8j4AhQzbR6XqawND7NPTECVdtLd",
|
||||
Category: "receive",
|
||||
Amount: 100,
|
||||
Fee: 0.0,
|
||||
Confirmations: 6707,
|
||||
Generated: false,
|
||||
BlockHash: "000000000b20bf5fe8e25b19f9ec340744cda321a17ade12af9838530a75098b",
|
||||
BlockIndex: 2,
|
||||
BlockTime: 1397079345,
|
||||
TxID: "cb082a63b29f446551829d03fa8bac02d3825a18994d5feec564f14101fc5fad",
|
||||
WalletConflicts: []string{},
|
||||
Time: 123123123,
|
||||
TimeReceived: 1397079169,
|
||||
Comment: "comment",
|
||||
OtherAccount: "",
|
||||
}
|
||||
return btcws.NewTxNtfn("abcde", details)
|
||||
},
|
||||
result: &btcws.TxNtfn{
|
||||
Account: "abcde",
|
||||
Details: map[string]interface{}{
|
||||
"key1": float64(12345),
|
||||
"key2": true,
|
||||
"key3": "lalala",
|
||||
"key4": []interface{}{"abcde", float64(12345)},
|
||||
Details: &btcjson.ListTransactionsResult{
|
||||
Account: "original",
|
||||
Address: "mnSsMBY8j4AhQzbR6XqawND7NPTECVdtLd",
|
||||
Category: "receive",
|
||||
Amount: 100,
|
||||
Fee: 0.0,
|
||||
Confirmations: 6707,
|
||||
Generated: false,
|
||||
BlockHash: "000000000b20bf5fe8e25b19f9ec340744cda321a17ade12af9838530a75098b",
|
||||
BlockIndex: 2,
|
||||
BlockTime: 1397079345,
|
||||
TxID: "cb082a63b29f446551829d03fa8bac02d3825a18994d5feec564f14101fc5fad",
|
||||
WalletConflicts: []string{},
|
||||
Time: 123123123,
|
||||
TimeReceived: 1397079169,
|
||||
Comment: "comment",
|
||||
OtherAccount: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue