Skip to content

Commit 5580d68

Browse files
committed
firewalldb: export DecodeChannelPoint and restrict
1 parent 6e30eca commit 5580d68

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
@@ -127,7 +127,7 @@ func TestPrivacyMapper(t *testing.T) {
127127
},
128128
{
129129
ChanId: 3446430762436373227,
130-
ChannelPoint: "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c62:1642614131",
130+
ChannelPoint: "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c:1642614131",
131131
},
132132
},
133133
},
@@ -287,7 +287,7 @@ func TestPrivacyMapper(t *testing.T) {
287287
"00000000000002a6": "7859bf41241787c2",
288288
"000000000000036c": "1320e5d25b7b5973",
289289
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:0": "097ef666a61919ff3413b3b701eae3a5cbac08f70c0ca567806e1fa6acbfe384:2161781494",
290-
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:1": "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c62:1642614131",
290+
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:1": "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c:1642614131",
291291
"01020304": "c8134495",
292292
}
293293

firewalldb/privacy_mapper.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func HideChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
393393
return "", 0, err
394394
}
395395
if err == nil {
396-
return decodeChannelPoint(pseudo)
396+
return DecodeChannelPoint(pseudo)
397397
}
398398

399399
newCp, err := NewPseudoChanPoint()
@@ -405,7 +405,7 @@ func HideChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
405405
return "", 0, err
406406
}
407407

408-
return decodeChannelPoint(newCp)
408+
return DecodeChannelPoint(newCp)
409409
}
410410

411411
func NewPseudoChanPoint() (string, error) {
@@ -427,7 +427,7 @@ func RevealChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
427427
return "", 0, err
428428
}
429429

430-
return decodeChannelPoint(real)
430+
return DecodeChannelPoint(real)
431431
}
432432

433433
func NewPseudoUint32() uint32 {
@@ -438,7 +438,7 @@ func NewPseudoUint32() uint32 {
438438
}
439439

440440
func HideChanPointStr(tx PrivacyMapTx, cp string) (string, error) {
441-
txid, index, err := decodeChannelPoint(cp)
441+
txid, index, err := DecodeChannelPoint(cp)
442442
if err != nil {
443443
return "", err
444444
}
@@ -500,7 +500,7 @@ func StrToUint64(s string) (uint64, error) {
500500
return binary.BigEndian.Uint64(b), nil
501501
}
502502

503-
func decodeChannelPoint(cp string) (string, uint32, error) {
503+
func DecodeChannelPoint(cp string) (string, uint32, error) {
504504
parts := strings.Split(cp, ":")
505505
if len(parts) != 2 {
506506
return "", 0, fmt.Errorf("bad channel point encoding")
@@ -511,6 +511,11 @@ func decodeChannelPoint(cp string) (string, uint32, error) {
511511
return "", 0, err
512512
}
513513

514+
if len(parts[0]) != txidStringLen {
515+
return "", 0, fmt.Errorf("wrong txid length want %v, got %v",
516+
txidStringLen, len(parts[0]))
517+
}
518+
514519
return parts[0], uint32(index), nil
515520
}
516521

0 commit comments

Comments
 (0)