-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (60 loc) · 1.61 KB
/
main.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 (
"crypto/ecdsa"
"fmt"
"log"
"math/big"
"os"
"sync"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/happyeric77/golangSolidityOracle/contractCtl"
"github.com/happyeric77/golangSolidityOracle/oracleServer"
"github.com/joho/godotenv"
)
func loadChainInfo() (*ethclient.Client, *ecdsa.PrivateKey, error) {
client, err := ethclient.Dial(fmt.Sprintf("wss://kovan.infura.io/ws/v3/%s", os.Getenv("INFURA_API_KEY")))
if err != nil {
log.Fatal(err)
}
privateKey, err := crypto.HexToECDSA(os.Getenv("PRIVATE_KEY"))
if err != nil {
return nil, nil, err
}
return client, privateKey, nil
}
func main() {
godotenv.Load("./.env")
client, privateKey, err := loadChainInfo()
if err != nil {
log.Fatal(err)
}
_ = client
_ = privateKey
// contractInstance, ca, txa, err := contractCtl.Deploy(client, privateKey)
// if err != nil {
// log.Fatal(err)
// }
// _ = contractInstance
// _ = ca
// _ = txa
oracleInstance, err := contractCtl.Load(client)
if err != nil {
log.Fatal()
}
currentPrice, err := oracleInstance.CurrencyPrice(nil)
if err != nil {
log.Fatal("ERR: main.go Get currentPrice fail")
}
fmt.Printf("Current Price: %v\n", currentPrice)
auth, err := contractCtl.TxOps(client, privateKey, 0)
if err != nil {
log.Fatal(fmt.Sprintf("ERR (contractCtl.Deply): %v\n", err))
}
var wg sync.WaitGroup
wg.Add(1)
go oracleServer.SubscribeEventLog(client, oracleInstance, privateKey)
tx, err := oracleInstance.RequestCurrencyPrice(auth, big.NewInt(10))
fmt.Printf("Request oracle to update price: %x", tx.Hash())
wg.Wait()
}