forked from ChainSafe/ChainBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic.go
33 lines (27 loc) · 914 Bytes
/
generic.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
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
package utils
import (
"github.com/kaelnew/chainbridge/bindings/GenericHandler"
"github.com/kaelnew/chainbridge-utils/msg"
"github.com/ethereum/go-ethereum/common"
)
var StoreFunctionSig = CreateFunctionSignature("store(bytes32)")
// CreateFunctionSignature hashes the function signature and returns the first 4 bytes
func CreateFunctionSignature(sig string) [4]byte {
var res [4]byte
hash := Hash([]byte(sig))
copy(res[:], hash[:])
return res
}
func GetGenericResourceAddress(client *Client, handler common.Address, rId msg.ResourceId) (common.Address, error) {
instance, err := GenericHandler.NewGenericHandler(handler, client.Client)
if err != nil {
return ZeroAddress, err
}
addr, err := instance.ResourceIDToContractAddress(client.CallOpts, rId)
if err != nil {
return ZeroAddress, err
}
return addr, nil
}