-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspecialTxCreator.go
73 lines (58 loc) · 1.27 KB
/
specialTxCreator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"encoding/hex"
"encoding/json"
"fmt"
)
type PatcherInput struct {
PatchAddr [20]byte
TargetAddr [20]byte
Nonce uint64
FuncSelector [4]byte
}
func Hex2Bytes(str string) []byte {
h, _ := hex.DecodeString(str)
return h
}
func FromHex(s string) []byte {
if len(s) > 1 {
if s[0:2] == "0x" || s[0:2] == "0X" {
s = s[2:]
}
if len(s)%2 == 1 {
s = "0" + s
}
return Hex2Bytes(s)
}
return nil
}
func BytesToAddress(b []byte) [20]byte {
var a [20]byte
if len(b) > 20 {
b = b[len(b)-20:]
}
copy(a[20-len(b):], b)
return a
}
func HexToAddress(s string) [20]byte { return BytesToAddress(FromHex(s)) }
func BytesliceToBytearray(s string) [4]byte {
tmp := FromHex(s)
var data [4]byte
for i := 0; i <= 3; i = i+1 {
data[i] = tmp[i]
}
return data
}
func Inputencoding(){
input := &PatcherInput{
PatchAddr: HexToAddress("0xFb2FBfC2381c82dC4D6Bbb34e851B9eBe47a0AC1"),
TargetAddr: HexToAddress("0x598dC737741B05df741D9bA284E9EdC21A46151f"),
Nonce: 36,
FuncSelector: BytesliceToBytearray("0x2e1a7d4d"),
}
payload, _ := json.Marshal(input)
fmt.Printf("The data of the special transaction: %x\n", payload)
}
func main() {
Inputencoding()
}