This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaas.go
88 lines (72 loc) · 2.1 KB
/
faas.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package faas
import (
"context"
"errors"
"log"
"strings"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/gabkov/krnl-node/client"
)
// simulate KYT database
// the first address from the local hardhat node config
var kytAddresses = []string{"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"}
func CallService(faas string, tx *types.Transaction) error {
switch strings.TrimSpace(faas) {
case "KYC":
return kyc(tx)
case "KYT":
return kyt(tx)
case "EL_KYT":
return elKYT(tx)
default:
log.Println("Unknown function name: ", faas)
return nil
}
}
func kyt(tx *types.Transaction) error {
from, err := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx)
if err != nil {
log.Fatal("Could not get sender")
}
sender := from.Hex()
for _, value := range kytAddresses {
if value == sender {
log.Println("KYT success for address: ", sender)
return nil
}
}
return errors.New("KYT failed for address " + from.Hex())
}
func kyc(tx *types.Transaction) error {
log.Println("KYC FaaS not implemented")
return nil
}
// In order to use elKYT the EigenLayer AVS needs to be running
// Instructions for that can be found here: https://github.com/martonmoro/krnl-el-kyt-avs
func elKYT(tx *types.Transaction) error {
// extract sender from the tx
from, err := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx)
if err != nil {
log.Fatal("Could not get sender")
}
// The address of the EigenLayer AVS Task Manager contract (kytTaskManager)
kytTaskManagerAddress := common.HexToAddress("0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E")
callMsg := ethereum.CallMsg{
To: &kytTaskManagerAddress,
From: from,
// getKYTForAddress()
Data: common.FromHex("0xaf5e8556"),
}
res, err := client.GetElClient().CallContract(context.Background(), callMsg, nil)
if err != nil {
log.Println("Error calling kyt contract: ", err)
return err
}
if res[len(res) -1] == byte(1) {
log.Println("EL KYT success for address: ", from.Hex())
return nil
}
return errors.New("EL KYT failed for address " + from.Hex())
}