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.
|
// unmarshaling of newtx JSON websocket notifications.
|
||||||
type TxNtfn struct {
|
type TxNtfn struct {
|
||||||
Account string
|
Account string
|
||||||
Details map[string]interface{}
|
Details *btcjson.ListTransactionsResult
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enforce that TxNtfn satisifies the btcjson.Cmd interface.
|
// Enforce that TxNtfn satisifies the btcjson.Cmd interface.
|
||||||
var _ btcjson.Cmd = &TxNtfn{}
|
var _ btcjson.Cmd = &TxNtfn{}
|
||||||
|
|
||||||
// NewTxNtfn creates a new 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{
|
return &TxNtfn{
|
||||||
Account: account,
|
Account: account,
|
||||||
Details: details,
|
Details: details,
|
||||||
|
@ -818,14 +818,13 @@ func parseTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) {
|
||||||
"string: " + err.Error())
|
"string: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(davec): Object
|
var details btcjson.ListTransactionsResult
|
||||||
var details map[string]interface{}
|
|
||||||
if err := json.Unmarshal(r.Params[1], &details); err != nil {
|
if err := json.Unmarshal(r.Params[1], &details); err != nil {
|
||||||
return nil, errors.New("second parameter 'details' must be a " +
|
return nil, errors.New("second parameter 'details' must be a " +
|
||||||
"JSON object of transaction details: " + err.Error())
|
"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
|
// Id satisifies the btcjson.Cmd interface by returning nil for a
|
||||||
|
|
|
@ -135,21 +135,45 @@ var ntfntests = []struct {
|
||||||
{
|
{
|
||||||
name: "newtx",
|
name: "newtx",
|
||||||
f: func() btcjson.Cmd {
|
f: func() btcjson.Cmd {
|
||||||
details := map[string]interface{}{
|
details := &btcjson.ListTransactionsResult{
|
||||||
"key1": float64(12345),
|
Account: "original",
|
||||||
"key2": true,
|
Address: "mnSsMBY8j4AhQzbR6XqawND7NPTECVdtLd",
|
||||||
"key3": "lalala",
|
Category: "receive",
|
||||||
"key4": []interface{}{"abcde", float64(12345)},
|
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)
|
return btcws.NewTxNtfn("abcde", details)
|
||||||
},
|
},
|
||||||
result: &btcws.TxNtfn{
|
result: &btcws.TxNtfn{
|
||||||
Account: "abcde",
|
Account: "abcde",
|
||||||
Details: map[string]interface{}{
|
Details: &btcjson.ListTransactionsResult{
|
||||||
"key1": float64(12345),
|
Account: "original",
|
||||||
"key2": true,
|
Address: "mnSsMBY8j4AhQzbR6XqawND7NPTECVdtLd",
|
||||||
"key3": "lalala",
|
Category: "receive",
|
||||||
"key4": []interface{}{"abcde", float64(12345)},
|
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