mirror of
https://github.com/status-im/op-geth.git
synced 2025-01-15 17:24:36 +00:00
Added Left and Right padding utility functions
This commit is contained in:
parent
6151ae7db5
commit
28ef7d228c
@ -118,7 +118,8 @@ func FormatData(data string) []byte {
|
|||||||
// Simple stupid
|
// Simple stupid
|
||||||
d := new(big.Int)
|
d := new(big.Int)
|
||||||
if data[0:1] == "\"" && data[len(data)-1:] == "\"" {
|
if data[0:1] == "\"" && data[len(data)-1:] == "\"" {
|
||||||
d.SetBytes([]byte(data[1 : len(data)-1]))
|
return RightPadBytes([]byte(data), 32)
|
||||||
|
//d.SetBytes([]byte(data[1 : len(data)-1]))
|
||||||
} else if len(data) > 1 && data[:2] == "0x" {
|
} else if len(data) > 1 && data[:2] == "0x" {
|
||||||
d.SetBytes(Hex2Bytes(data[2:]))
|
d.SetBytes(Hex2Bytes(data[2:]))
|
||||||
} else {
|
} else {
|
||||||
@ -127,3 +128,25 @@ func FormatData(data string) []byte {
|
|||||||
|
|
||||||
return BigToBytes(d, 256)
|
return BigToBytes(d, 256)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LeftPadBytes(slice []byte, l int) []byte {
|
||||||
|
if l <= len(slice) {
|
||||||
|
return slice
|
||||||
|
}
|
||||||
|
|
||||||
|
padded := make([]byte, l)
|
||||||
|
copy(padded[0:len(slice)], slice)
|
||||||
|
|
||||||
|
return padded
|
||||||
|
}
|
||||||
|
|
||||||
|
func RightPadBytes(slice []byte, l int) []byte {
|
||||||
|
if l <= len(slice) {
|
||||||
|
return slice
|
||||||
|
}
|
||||||
|
|
||||||
|
padded := make([]byte, l)
|
||||||
|
copy(padded[l-len(slice):], slice)
|
||||||
|
|
||||||
|
return padded
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user