mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
firewalldb: export DecodeChannelPoint and restrict
This commit is contained in:
parent
6e30ecaa69
commit
5580d6861d
2 changed files with 12 additions and 7 deletions
|
|
@ -127,7 +127,7 @@ func TestPrivacyMapper(t *testing.T) {
|
|||
},
|
||||
{
|
||||
ChanId: 3446430762436373227,
|
||||
ChannelPoint: "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c62:1642614131",
|
||||
ChannelPoint: "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c:1642614131",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -287,7 +287,7 @@ func TestPrivacyMapper(t *testing.T) {
|
|||
"00000000000002a6": "7859bf41241787c2",
|
||||
"000000000000036c": "1320e5d25b7b5973",
|
||||
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:0": "097ef666a61919ff3413b3b701eae3a5cbac08f70c0ca567806e1fa6acbfe384:2161781494",
|
||||
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:1": "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c62:1642614131",
|
||||
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd:1": "45ec471bfccb0b7b9a8bc4008248931c59ad994903e07b54f54821ea3ef5cc5c:1642614131",
|
||||
"01020304": "c8134495",
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ func HideChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
|
|||
return "", 0, err
|
||||
}
|
||||
if err == nil {
|
||||
return decodeChannelPoint(pseudo)
|
||||
return DecodeChannelPoint(pseudo)
|
||||
}
|
||||
|
||||
newCp, err := NewPseudoChanPoint()
|
||||
|
|
@ -405,7 +405,7 @@ func HideChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
|
|||
return "", 0, err
|
||||
}
|
||||
|
||||
return decodeChannelPoint(newCp)
|
||||
return DecodeChannelPoint(newCp)
|
||||
}
|
||||
|
||||
func NewPseudoChanPoint() (string, error) {
|
||||
|
|
@ -427,7 +427,7 @@ func RevealChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
|
|||
return "", 0, err
|
||||
}
|
||||
|
||||
return decodeChannelPoint(real)
|
||||
return DecodeChannelPoint(real)
|
||||
}
|
||||
|
||||
func NewPseudoUint32() uint32 {
|
||||
|
|
@ -438,7 +438,7 @@ func NewPseudoUint32() uint32 {
|
|||
}
|
||||
|
||||
func HideChanPointStr(tx PrivacyMapTx, cp string) (string, error) {
|
||||
txid, index, err := decodeChannelPoint(cp)
|
||||
txid, index, err := DecodeChannelPoint(cp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -500,7 +500,7 @@ func StrToUint64(s string) (uint64, error) {
|
|||
return binary.BigEndian.Uint64(b), nil
|
||||
}
|
||||
|
||||
func decodeChannelPoint(cp string) (string, uint32, error) {
|
||||
func DecodeChannelPoint(cp string) (string, uint32, error) {
|
||||
parts := strings.Split(cp, ":")
|
||||
if len(parts) != 2 {
|
||||
return "", 0, fmt.Errorf("bad channel point encoding")
|
||||
|
|
@ -511,6 +511,11 @@ func decodeChannelPoint(cp string) (string, uint32, error) {
|
|||
return "", 0, err
|
||||
}
|
||||
|
||||
if len(parts[0]) != txidStringLen {
|
||||
return "", 0, fmt.Errorf("wrong txid length want %v, got %v",
|
||||
txidStringLen, len(parts[0]))
|
||||
}
|
||||
|
||||
return parts[0], uint32(index), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue