-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcall.go
52 lines (42 loc) · 1.07 KB
/
call.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
package eth
import (
"context"
"errors"
"fmt"
"github.com/AlexNa-Holdings/web3pro/bus"
"github.com/AlexNa-Holdings/web3pro/cmn"
"github.com/ethereum/go-ethereum"
"github.com/rs/zerolog/log"
)
func call(msg *bus.Message) (string, error) {
req, ok := msg.Data.(*bus.B_EthCall)
if !ok {
return "", fmt.Errorf("invalid tx: %v", msg.Data)
}
w := cmn.CurrentWallet
if w == nil {
return "", errors.New("no wallet")
}
b := w.GetBlockchain(req.ChainId)
if b == nil {
return "", fmt.Errorf("call: blockchain not found: %v", req.ChainId)
}
c, ok := cons[b.ChainId]
if !ok {
log.Error().Msgf("SendSignedTx: Client not found for chainId: %d", b.ChainId)
return "", fmt.Errorf("client not found for chainId: %d", b.ChainId)
}
call_msg := ethereum.CallMsg{
To: &req.To,
From: req.From,
Value: req.Amount,
Data: req.Data,
}
output, err := c.CallContract(context.Background(), call_msg, nil)
if err != nil {
log.Error().Msgf("call: Cannot call contract. Error:(%v)", err)
return "", err
}
hex_data := fmt.Sprintf("0x%x", output)
return hex_data, nil
}