Skip to content

Commit 3112fdc

Browse files
committed
firewalldb: export DecodeChannelPoint and restrict
1 parent 967304b commit 3112fdc

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

firewall/privacy_mapper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestPrivacyMapper(t *testing.T) {
126126
},
127127
{
128128
ChanId: 3446430762436373227,
129-
ChannelPoint: "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c62:1642614131",
129+
ChannelPoint: "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c:1642614131",
130130
},
131131
},
132132
},
@@ -286,7 +286,7 @@ func TestPrivacyMapper(t *testing.T) {
286286
"00000000000002a6": "7859bf41241787c2",
287287
"000000000000036c": "1320e5d25b7b5973",
288288
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:0": "097ef666a61919ff3413b3b701eae3a5cbac08f70c0ca567806e1fa6acbfe384:2161781494",
289-
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:1": "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c62:1642614131",
289+
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:1": "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c:1642614131",
290290
"01020304": "c8134495",
291291
}
292292

firewalldb/privacy_mapper.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func HideChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
340340
return "", 0, err
341341
}
342342
if err == nil {
343-
return decodeChannelPoint(pseudo)
343+
return DecodeChannelPoint(pseudo)
344344
}
345345

346346
newCp, err := NewPseudoChanPoint()
@@ -352,7 +352,7 @@ func HideChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
352352
return "", 0, err
353353
}
354354

355-
return decodeChannelPoint(newCp)
355+
return DecodeChannelPoint(newCp)
356356
}
357357

358358
func NewPseudoChanPoint() (string, error) {
@@ -374,7 +374,7 @@ func RevealChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
374374
return "", 0, err
375375
}
376376

377-
return decodeChannelPoint(real)
377+
return DecodeChannelPoint(real)
378378
}
379379

380380
func NewPseudoUint32() uint32 {
@@ -385,7 +385,7 @@ func NewPseudoUint32() uint32 {
385385
}
386386

387387
func HideChanPointStr(tx PrivacyMapTx, cp string) (string, error) {
388-
txid, index, err := decodeChannelPoint(cp)
388+
txid, index, err := DecodeChannelPoint(cp)
389389
if err != nil {
390390
return "", err
391391
}
@@ -447,7 +447,7 @@ func StrToUint64(s string) (uint64, error) {
447447
return binary.BigEndian.Uint64(b), nil
448448
}
449449

450-
func decodeChannelPoint(cp string) (string, uint32, error) {
450+
func DecodeChannelPoint(cp string) (string, uint32, error) {
451451
parts := strings.Split(cp, ":")
452452
if len(parts) != 2 {
453453
return "", 0, fmt.Errorf("bad channel point encoding")
@@ -458,5 +458,10 @@ func decodeChannelPoint(cp string) (string, uint32, error) {
458458
return "", 0, err
459459
}
460460

461+
if len(parts[0]) != txidStringLen {
462+
return "", 0, fmt.Errorf("wrong txid length want %v, got %v",
463+
txidStringLen, len(parts[0]))
464+
}
465+
461466
return parts[0], uint32(index), nil
462467
}

0 commit comments

Comments
 (0)