Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions btcjson/dashevocmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ type QuorumCmd struct {
LLMQType *LLMQType `json:",omitempty"`
RequestID *string `json:",omitempty"`
MessageHash *string `json:",omitempty"`
QuorumHash *string `json:",omitempty"`
Signature *string `json:",omitempty"`
QuorumHash *string `json:",omitempty"`

Submit *bool `json:",omitempty"`
IncludeSkShare *bool `json:",omitempty"`
Expand Down Expand Up @@ -593,8 +593,8 @@ func unmarshalQuorumLLMQType(next unmarshalQuorumCmdFunc) unmarshalQuorumCmdFunc
func quorumVerifyUnmarshaler(q *QuorumCmd, args []interface{}) error {
q.RequestID = strPtr(args[1].(string))
q.MessageHash = strPtr(args[2].(string))
q.QuorumHash = strPtr(args[3].(string))
q.Signature = strPtr(args[4].(string))
q.Signature = strPtr(args[3].(string))
q.QuorumHash = strPtr(args[4].(string))
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions btcjson/dashevocmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ func TestDashpayCmds(t *testing.T) {
btcjson.LLMQType_100_67,
"0067c4fd779a195a95b267e263c631f71f83f8d5e6191091289d114012b373a1",
"ce490ca26cad6f1749ff9b977fe0fe4ece4391166f69be75c4619bc94b184dbc",
"5f1018f54507606069303fd16257434073c6f374729b0090bb9dbbe629241235",
"6f1018f54507606069303fd16257434073c6f374729b0090bb9dbbe629241236",
"5f1018f54507606069303fd16257434073c6f374729b0090bb9dbbe629241235")
)
},
staticCmd: func() interface{} {
return btcjson.NewQuorumVerifyCmd(btcjson.LLMQType_100_67,
Expand All @@ -124,7 +125,7 @@ func TestDashpayCmds(t *testing.T) {
"5f1018f54507606069303fd16257434073c6f374729b0090bb9dbbe629241235",
"6f1018f54507606069303fd16257434073c6f374729b0090bb9dbbe629241236")
},
marshalled: `{"jsonrpc":"1.0","method":"quorum","params":["verify",4,"0067c4fd779a195a95b267e263c631f71f83f8d5e6191091289d114012b373a1","ce490ca26cad6f1749ff9b977fe0fe4ece4391166f69be75c4619bc94b184dbc","6f1018f54507606069303fd16257434073c6f374729b0090bb9dbbe629241236","5f1018f54507606069303fd16257434073c6f374729b0090bb9dbbe629241235"],"id":1}`,
marshalled: `{"jsonrpc":"1.0","method":"quorum","params":["verify",4,"0067c4fd779a195a95b267e263c631f71f83f8d5e6191091289d114012b373a1","ce490ca26cad6f1749ff9b977fe0fe4ece4391166f69be75c4619bc94b184dbc","5f1018f54507606069303fd16257434073c6f374729b0090bb9dbbe629241235","6f1018f54507606069303fd16257434073c6f374729b0090bb9dbbe629241236"],"id":1}`,
unmarshalled: &btcjson.QuorumCmd{
SubCmd: "verify",
LLMQType: pLLMQType(btcjson.LLMQType_100_67),
Expand Down
23 changes: 22 additions & 1 deletion btcjson/dashevoresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,28 @@ type QuorumSignResultWithBool struct {
// returns a boolean.
type QuorumVerifyResult struct {
// Result is the output if submit was true
Result bool `json:"result,omitempty"`
Result bool `json:"result"`
}

// UnmarshalJSON is a custom unmarshal because the result can be just a boolean
func (qvr *QuorumVerifyResult) UnmarshalJSON(data []byte) error {
if bl, err := strconv.ParseBool(string(data)); err == nil {
qvr.Result = bl
return nil
}

var result bool
err := json.Unmarshal(data, &result)
if err != nil {
return err
}
// Cast the new type instance to the original type and assign.
qvr.Result = result
return nil
}

func (qvr QuorumVerifyResult) MarshalJSON() ([]byte, error) {
return json.Marshal(qvr.Result)
}

// UnmarshalJSON is a custom unmarshal because the result can be just a boolean
Expand Down
61 changes: 58 additions & 3 deletions btcjson/dashevoresults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package btcjson_test

import (
"encoding/json"
"github.com/dashpay/dashd-go/btcjson"
"testing"

"github.com/dashpay/dashd-go/btcjson"
)

// TestDashQuorumSignResults ensures QuorumSignResults are unmarshalled correctly
Expand Down Expand Up @@ -39,11 +40,65 @@ func TestDashQuorumSignResults(t *testing.T) {
continue
}
if string(marshalled) != test.expected {
t.Errorf("Test #%d (%s) unexpected marhsalled data - "+
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
"got %s, want %s", i, test.name, marshalled,
test.expected)
continue
}
}
}

// TestDashQuorumVerifyResults ensures QuorumVerifyResults are unmarshalled correctly
func TestDashQuorumVerifyResults(t *testing.T) {
t.Parallel()

tests := []struct {
name string
expected string
result btcjson.QuorumVerifyResult
}{
{
name: "quorum verify",
expected: `true`,
result: btcjson.QuorumVerifyResult{
Result: true,
},
},
{
name: "quorum verify",
expected: `false`,
result: btcjson.QuorumVerifyResult{
Result: false,
},
},
}

t.Logf("Running %d tests", len(tests))
for i, test := range tests {
marshalled, err := json.Marshal(test.result)
if err != nil {
t.Errorf("Test #%d (%s) unexpected error: %v", i,
test.name, err)
continue
}
if string(marshalled) != test.expected {
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
"got %s, want %s", i, test.name, marshalled,
test.expected)
continue
}

var unmarshalled btcjson.QuorumVerifyResult
if err := json.Unmarshal([]byte(test.expected), &unmarshalled); err != nil {
t.Errorf("Test #%d (%s) unexpected error: %v", i, test.name, err)
continue
}
if unmarshalled.Result != test.result.Result {
t.Errorf("Test #%d (%s) unexpected unmarshalled data - "+
"got %v, want %v", i, test.name, unmarshalled.Result,
test.result.Result)
continue
}
}
}

Expand Down Expand Up @@ -99,7 +154,7 @@ func TestDashQuorumInfoResults(t *testing.T) {
continue
}
if string(marshalled) != test.expected {
t.Errorf("Test #%d (%s) unexpected marhsalled data - "+
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
"got %s, want %s", i, test.name, marshalled,
test.expected)
continue
Expand Down
8 changes: 6 additions & 2 deletions rpcclient/evo.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,15 @@ func (c *Client) QuorumVerifyAsync(quorumType btcjson.LLMQType, requestID string

// QuorumVerify returns a true if the signature is valid and false if not
func (c *Client) QuorumVerify(quorumType btcjson.LLMQType, requestID string, messageHash string, signature string, quorumHash string) (bool, error) {
r, err := c.QuorumVerifyAsync(quorumType, requestID, messageHash, signature, quorumHash).Receive()
result, err := c.QuorumVerifyAsync(quorumType, requestID, messageHash, signature, quorumHash).Receive()
if err != nil {
return false, err
}
return r.Result, nil
if result == nil {
return false, fmt.Errorf("no result")
}

return bool(result.Result), nil
}

// ----------------------------- quorum info -----------------------------
Expand Down
Loading