This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
/
service.go
105 lines (84 loc) · 2.57 KB
/
service.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package service
import (
"context"
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/medibloc/panacea-doracle/config"
"github.com/medibloc/panacea-doracle/event"
"github.com/medibloc/panacea-doracle/ipfs"
"github.com/medibloc/panacea-doracle/panacea"
"github.com/medibloc/panacea-doracle/sgx"
dbm "github.com/tendermint/tm-db"
)
type TestServiceWithoutSGX struct {
conf *config.Config
oracleAccount *panacea.OracleAccount
oraclePrivKey *btcec.PrivateKey
queryClient *panacea.QueryClient
grpcClient *panacea.GrpcClient
subscriber *event.PanaceaSubscriber
ipfs *ipfs.Ipfs
}
func (s *TestServiceWithoutSGX) BroadcastTx(txBytes []byte) (int64, string, error) {
resp, err := s.GRPCClient().BroadcastTx(txBytes)
if err != nil {
return 0, "", fmt.Errorf("broadcast transaction failed. txBytes(%v)", txBytes)
}
if resp.TxResponse.Code != 0 {
return 0, "", fmt.Errorf("transaction failed: %v", resp.TxResponse.RawLog)
}
return resp.TxResponse.Height, resp.TxResponse.TxHash, nil
}
func NewTestServiceWithoutSGX(conf *config.Config, info *panacea.TrustedBlockInfo) (*TestServiceWithoutSGX, error) {
oracleAccount, err := panacea.NewOracleAccount(conf.OracleMnemonic, conf.OracleAccNum, conf.OracleAccIndex)
if err != nil {
return nil, err
}
oraclePrivKey, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
return nil, err
}
queryClient, err := panacea.NewQueryClientWithDB(context.Background(), conf, info, dbm.NewMemDB())
if err != nil {
return nil, err
}
grpcClient, err := panacea.NewGrpcClient(conf.Panacea.GRPCAddr)
if err != nil {
return nil, err
}
panaceaSubscriber, err := event.NewSubscriber(conf.Panacea.RPCAddr)
if err != nil {
return nil, err
}
ipfs := ipfs.NewIpfs(conf.Ipfs.IpfsNodeAddr)
return &TestServiceWithoutSGX{
conf: conf,
oracleAccount: oracleAccount,
oraclePrivKey: oraclePrivKey,
queryClient: queryClient,
grpcClient: grpcClient,
subscriber: panaceaSubscriber,
ipfs: ipfs,
}, nil
}
func (s *TestServiceWithoutSGX) Config() *config.Config {
return s.conf
}
func (s *TestServiceWithoutSGX) OracleAcc() *panacea.OracleAccount {
return s.oracleAccount
}
func (s *TestServiceWithoutSGX) OraclePrivKey() *btcec.PrivateKey {
return s.oraclePrivKey
}
func (s *TestServiceWithoutSGX) EnclaveInfo() *sgx.EnclaveInfo {
return nil
}
func (s *TestServiceWithoutSGX) GRPCClient() *panacea.GrpcClient {
return s.grpcClient
}
func (s *TestServiceWithoutSGX) QueryClient() *panacea.QueryClient {
return s.queryClient
}
func (s *TestServiceWithoutSGX) Ipfs() *ipfs.Ipfs {
return s.ipfs
}