mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-07-03 03:12:30 +00:00
Update for latest btcjson API changes.
This commit modifies the AllVerboseTxNtfn command to use a parser along with the standard btcjson.RegisterCustomCmd instead of the now removed RegisterCustomCmdGenerator function. This is possible due to the recent changes that defers the unmarshalling of the parameters of a RawCmd to the parser.
This commit is contained in:
parent
6f08ca8a8a
commit
fc07555ad3
@ -85,8 +85,8 @@ func init() {
|
|||||||
parseWalletLockStateNtfn, `TODO(jrick) fillmein`)
|
parseWalletLockStateNtfn, `TODO(jrick) fillmein`)
|
||||||
btcjson.RegisterCustomCmd(AllTxNtfnMethod,
|
btcjson.RegisterCustomCmd(AllTxNtfnMethod,
|
||||||
parseAllTxNtfn, `TODO(flam) fillmein`)
|
parseAllTxNtfn, `TODO(flam) fillmein`)
|
||||||
btcjson.RegisterCustomCmdGenerator(AllVerboseTxNtfnMethod,
|
btcjson.RegisterCustomCmd(AllVerboseTxNtfnMethod,
|
||||||
generateAllVerboseTxNtfn)
|
parseAllVerboseTxNtfn, `TODO(flam) fillmein`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockDetails describes details of a tx in a block.
|
// BlockDetails describes details of a tx in a block.
|
||||||
@ -1099,6 +1099,26 @@ func NewAllVerboseTxNtfn(rawTx *btcjson.TxRawResult) *AllVerboseTxNtfn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parseAllVerboseTxNtfn parses a RawCmd into a concrete type satisifying
|
||||||
|
// the btcjson.Cmd interface. This is used when registering the notification
|
||||||
|
// with the btcjson parser.
|
||||||
|
func parseAllVerboseTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) {
|
||||||
|
if r.Id != nil {
|
||||||
|
return nil, ErrNotANtfn
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(r.Params) != 1 {
|
||||||
|
return nil, btcjson.ErrWrongNumberOfParams
|
||||||
|
}
|
||||||
|
|
||||||
|
var rawTx *btcjson.TxRawResult
|
||||||
|
if err := json.Unmarshal(r.Params[0], &rawTx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewAllVerboseTxNtfn(rawTx), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Id satisifies the btcjson.Cmd interface by returning nil for a
|
// Id satisifies the btcjson.Cmd interface by returning nil for a
|
||||||
// notification ID.
|
// notification ID.
|
||||||
func (n *AllVerboseTxNtfn) Id() interface{} {
|
func (n *AllVerboseTxNtfn) Id() interface{} {
|
||||||
@ -1130,10 +1150,6 @@ func (n *AllVerboseTxNtfn) MarshalJSON() ([]byte, error) {
|
|||||||
return json.Marshal(raw)
|
return json.Marshal(raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateAllVerboseTxNtfn() btcjson.Cmd {
|
|
||||||
return new(AllVerboseTxNtfn)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of
|
// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of
|
||||||
// the btcjson.Cmd interface.
|
// the btcjson.Cmd interface.
|
||||||
func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error {
|
func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error {
|
||||||
@ -1142,19 +1158,15 @@ func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Id != nil {
|
newNtfn, err := parseAllVerboseTxNtfn(&r)
|
||||||
return ErrNotANtfn
|
if err != nil {
|
||||||
}
|
|
||||||
|
|
||||||
if len(r.Params) != 1 {
|
|
||||||
return btcjson.ErrWrongNumberOfParams
|
|
||||||
}
|
|
||||||
|
|
||||||
var rawTx *btcjson.TxRawResult
|
|
||||||
if err := json.Unmarshal(r.Params[0], &rawTx); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
*n = *NewAllVerboseTxNtfn(rawTx)
|
concreteNtfn, ok := newNtfn.(*AllVerboseTxNtfn)
|
||||||
|
if !ok {
|
||||||
|
return btcjson.ErrInternal
|
||||||
|
}
|
||||||
|
*n = *concreteNtfn
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user