File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ package utils
2
+
3
+ import (
4
+ "encoding/binary"
5
+
6
+ "github.com/maticnetwork/polyproto/heimdall"
7
+ )
8
+
9
+ func ConvertH160toAddress (h160 * heimdall.H160 ) [20 ]byte {
10
+ var addr [20 ]byte
11
+
12
+ binary .BigEndian .PutUint64 (addr [0 :], h160 .Hi .Hi )
13
+ binary .BigEndian .PutUint64 (addr [8 :], h160 .Hi .Lo )
14
+ binary .BigEndian .PutUint32 (addr [16 :], h160 .Lo )
15
+
16
+ return addr
17
+ }
18
+
19
+ func ConvertAddressToH160 (addr [20 ]byte ) * heimdall.H160 {
20
+ return & heimdall.H160 {
21
+ Lo : binary .BigEndian .Uint32 (addr [16 :]),
22
+ Hi : & heimdall.H128 {Lo : binary .BigEndian .Uint64 (addr [8 :]), Hi : binary .BigEndian .Uint64 (addr [0 :])},
23
+ }
24
+ }
25
+
26
+ func ConvertH256ToHash (h256 * heimdall.H256 ) [32 ]byte {
27
+ var hash [32 ]byte
28
+
29
+ binary .BigEndian .PutUint64 (hash [0 :], h256 .Hi .Hi )
30
+ binary .BigEndian .PutUint64 (hash [8 :], h256 .Hi .Lo )
31
+ binary .BigEndian .PutUint64 (hash [16 :], h256 .Lo .Hi )
32
+ binary .BigEndian .PutUint64 (hash [24 :], h256 .Lo .Lo )
33
+
34
+ return hash
35
+ }
36
+
37
+ func ConvertHashToH256 (hash [32 ]byte ) * heimdall.H256 {
38
+ return & heimdall.H256 {
39
+ Lo : & heimdall.H128 {Lo : binary .BigEndian .Uint64 (hash [24 :]), Hi : binary .BigEndian .Uint64 (hash [16 :])},
40
+ Hi : & heimdall.H128 {Lo : binary .BigEndian .Uint64 (hash [8 :]), Hi : binary .BigEndian .Uint64 (hash [0 :])},
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments