Skip to content

Commit 07353d6

Browse files
authored
Merge pull request #96 from florent-uzio/fix/quorum
Updated SignerQuorum in SignerListSet to be an interface{} with uint32 type assertion instead of a value (uint32).
2 parents 8148bdb + 7a655b7 commit 07353d6

File tree

5 files changed

+66
-19
lines changed

5 files changed

+66
-19
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [v0.1.4]
9+
10+
### Fixed
11+
12+
#### xrpl
13+
14+
- Updated SignerQuorum in SignerListSet to be an interface{} with uint32 type assertion instead of a value (uint32).
15+
- This allows distinguishing between an unset (nil) and an explicitly set value, including 0 to delete a signer list.
16+
- Ensures SignerQuorum is only included in the Flatten() output when explicitly defined.
17+
- Updates the `Validate` method to make sure `SignerEntries` is not set when `SignerQuorum` is set to 0
18+
19+
## [v0.1.3]
920

1021
### Added
1122

examples/multisigning/rpc/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070
BaseTx: transaction.BaseTx{
7171
Account: master.GetAddress(),
7272
},
73-
SignerQuorum: 2,
73+
SignerQuorum: uint32(2),
7474
SignerEntries: []ledger.SignerEntryWrapper{
7575
{
7676
SignerEntry: ledger.SignerEntry{

examples/multisigning/ws/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func main() {
8181
BaseTx: transaction.BaseTx{
8282
Account: master.GetAddress(),
8383
},
84-
SignerQuorum: 2,
84+
SignerQuorum: uint32(2),
8585
SignerEntries: []ledger.SignerEntryWrapper{
8686
{
8787
SignerEntry: ledger.SignerEntry{

xrpl/transaction/signer_list_set.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var (
1313
ErrInvalidSignerEntries = fmt.Errorf("signerEntries must have at least %d entry and no more than %d entries", MinSigners, MaxSigners)
1414
ErrInvalidWalletLocator = errors.New("invalid WalletLocator in SignerEntry, must be an hexadecimal string")
1515
ErrSignerQuorumGreaterThanSumOfSignerWeights = errors.New("signerQuorum must be less than or equal to the sum of all SignerWeights")
16+
ErrInvalidQuorumAndEntries = errors.New("signerEntries must be empty when the SignerQuorum is set to 0 to delete a signer list")
1617
)
1718

1819
const (
@@ -61,8 +62,8 @@ const (
6162
type SignerListSet struct {
6263
BaseTx
6364
// A target number for the signer weights. A multi-signature from this list is valid only if the sum weights of the signatures provided is greater than or equal to this value.
64-
// To delete a signer list, use the value 0.
65-
SignerQuorum uint32
65+
// To delete a signer list, use the value 0. Needs to be an uint32.
66+
SignerQuorum interface{}
6667
// (Omitted when deleting) Array of SignerEntry objects, indicating the addresses and weights of signers in this list.
6768
// This signer list must have at least 1 member and no more than 32 members.
6869
// No address may appear more than once in the list, nor may the Account submitting the transaction appear in the list.
@@ -80,7 +81,7 @@ func (s *SignerListSet) Flatten() FlatTransaction {
8081

8182
flattened["TransactionType"] = "SignerListSet"
8283

83-
if s.SignerQuorum != 0 {
84+
if s.SignerQuorum != nil {
8485
flattened["SignerQuorum"] = s.SignerQuorum
8586
}
8687

@@ -105,11 +106,18 @@ func (s *SignerListSet) Validate() (bool, error) {
105106
return false, err
106107
}
107108

109+
sq, ok := s.SignerQuorum.(uint32)
110+
zeroQuorum := ((ok && sq == uint32(0)) || s.SignerQuorum == nil)
111+
108112
// All other checks are for if SignerQuorum is greater than 0
109-
if s.SignerQuorum == 0 {
113+
if zeroQuorum && len(s.SignerEntries) == 0 {
110114
return true, nil
111115
}
112116

117+
if zeroQuorum && len(s.SignerEntries) > 0 {
118+
return false, ErrInvalidQuorumAndEntries
119+
}
120+
113121
// Check if SignerEntries has at least 1 entry and no more than 32 entries
114122
if len(s.SignerEntries) < MinSigners || len(s.SignerEntries) > MaxSigners {
115123
return false, ErrInvalidSignerEntries
@@ -132,7 +140,7 @@ func (s *SignerListSet) Validate() (bool, error) {
132140
for _, signerEntry := range s.SignerEntries {
133141
sumSignerWeights += signerEntry.SignerEntry.SignerWeight
134142
}
135-
if s.SignerQuorum > uint32(sumSignerWeights) {
143+
if sq > uint32(sumSignerWeights) {
136144
return false, ErrSignerQuorumGreaterThanSumOfSignerWeights
137145
}
138146

xrpl/transaction/signer_list_set_test.go

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestSignerListSet_Flatten(t *testing.T) {
2828
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
2929
Fee: types.XRPCurrencyAmount(12),
3030
},
31-
SignerQuorum: 3,
31+
SignerQuorum: uint32(3),
3232
SignerEntries: []ledger.SignerEntryWrapper{
3333
{
3434
SignerEntry: ledger.SignerEntry{
@@ -84,12 +84,13 @@ func TestSignerListSet_Flatten(t *testing.T) {
8484
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
8585
Fee: types.XRPCurrencyAmount(12),
8686
},
87-
SignerQuorum: 0,
87+
SignerQuorum: uint32(0),
8888
},
8989
expected: `{
9090
"TransactionType": "SignerListSet",
9191
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
92-
"Fee": "12"
92+
"Fee": "12",
93+
"SignerQuorum": 0
9394
}`,
9495
},
9596
{
@@ -132,7 +133,7 @@ func TestSignerListSet_Validate(t *testing.T) {
132133
TransactionType: SignerListSetTx,
133134
Fee: types.XRPCurrencyAmount(12),
134135
},
135-
SignerQuorum: 3,
136+
SignerQuorum: uint32(3),
136137
SignerEntries: []ledger.SignerEntryWrapper{
137138
{
138139
SignerEntry: ledger.SignerEntry{
@@ -167,7 +168,7 @@ func TestSignerListSet_Validate(t *testing.T) {
167168
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
168169
Fee: types.XRPCurrencyAmount(12),
169170
},
170-
SignerQuorum: 3,
171+
SignerQuorum: uint32(3),
171172
SignerEntries: []ledger.SignerEntryWrapper{
172173
{
173174
SignerEntry: ledger.SignerEntry{
@@ -194,7 +195,7 @@ func TestSignerListSet_Validate(t *testing.T) {
194195
TransactionType: SignerListSetTx,
195196
Fee: types.XRPCurrencyAmount(12),
196197
},
197-
SignerQuorum: 3,
198+
SignerQuorum: uint32(3),
198199
},
199200
wantValid: false,
200201
wantErr: true,
@@ -207,7 +208,7 @@ func TestSignerListSet_Validate(t *testing.T) {
207208
TransactionType: SignerListSetTx,
208209
Fee: types.XRPCurrencyAmount(12),
209210
},
210-
SignerQuorum: 3,
211+
SignerQuorum: uint32(3),
211212
SignerEntries: func() []ledger.SignerEntryWrapper {
212213
entries := make([]ledger.SignerEntryWrapper, 33)
213214
for i := range entries {
@@ -232,7 +233,7 @@ func TestSignerListSet_Validate(t *testing.T) {
232233
TransactionType: SignerListSetTx,
233234
Fee: types.XRPCurrencyAmount(12),
234235
},
235-
SignerQuorum: 3,
236+
SignerQuorum: uint32(3),
236237
SignerEntries: []ledger.SignerEntryWrapper{
237238
{
238239
SignerEntry: ledger.SignerEntry{
@@ -254,7 +255,7 @@ func TestSignerListSet_Validate(t *testing.T) {
254255
TransactionType: SignerListSetTx,
255256
Fee: types.XRPCurrencyAmount(12),
256257
},
257-
SignerQuorum: 5,
258+
SignerQuorum: uint32(5),
258259
SignerEntries: []ledger.SignerEntryWrapper{
259260
{
260261
SignerEntry: ledger.SignerEntry{
@@ -281,7 +282,7 @@ func TestSignerListSet_Validate(t *testing.T) {
281282
TransactionType: SignerListSetTx,
282283
Fee: types.XRPCurrencyAmount(12),
283284
},
284-
SignerQuorum: 2,
285+
SignerQuorum: uint32(2),
285286
SignerEntries: []ledger.SignerEntryWrapper{
286287
{
287288
SignerEntry: ledger.SignerEntry{
@@ -308,11 +309,38 @@ func TestSignerListSet_Validate(t *testing.T) {
308309
TransactionType: SignerListSetTx,
309310
Fee: types.XRPCurrencyAmount(12),
310311
},
311-
SignerQuorum: 0,
312+
SignerQuorum: uint32(0),
312313
},
313314
wantValid: true,
314315
wantErr: false,
315316
},
317+
{
318+
name: "fail - invalid SignerListSet with SignerQuorum 0 but a SignerEntries not empty",
319+
entry: &SignerListSet{
320+
BaseTx: BaseTx{
321+
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
322+
TransactionType: SignerListSetTx,
323+
Fee: types.XRPCurrencyAmount(12),
324+
},
325+
SignerQuorum: uint32(0),
326+
SignerEntries: []ledger.SignerEntryWrapper{
327+
{
328+
SignerEntry: ledger.SignerEntry{
329+
Account: "invalid",
330+
SignerWeight: 2,
331+
},
332+
},
333+
{
334+
SignerEntry: ledger.SignerEntry{
335+
Account: "rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v",
336+
SignerWeight: 1,
337+
},
338+
},
339+
},
340+
},
341+
wantValid: false,
342+
wantErr: true,
343+
},
316344
}
317345

318346
for _, tt := range tests {

0 commit comments

Comments
 (0)