/
api.go
92 lines (78 loc) · 2.72 KB
/
api.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
package pbft
import (
"encoding/json"
"github.com/PhoenixGlobal/Phoenix-Chain-SDK/consensus/pbft/state"
"github.com/PhoenixGlobal/Phoenix-Chain-SDK/consensus/pbft/types"
"github.com/PhoenixGlobal/Phoenix-Chain-SDK/libs/crypto/bls"
)
type Status struct {
Tree *types.BlockTree `json:"blockTree"`
State *state.ViewState `json:"state"`
Validator bool `json:"validator"`
}
// API defines an exposed API function interface.
type API interface {
Status() []byte
Evidences() string
GetPrepareQC(number uint64) *types.QuorumCert
GetSchnorrNIZKProve() (*bls.SchnorrProof, error)
}
// PublicDebugConsensusAPI provides an API to access the PhoenixChain blockchain.
// It offers only methods that operate on public data that
// is freely available to anyone.
type PublicDebugConsensusAPI struct {
engine API
}
// NewDebugConsensusAPI creates a new PhoenixChain blockchain API.
func NewDebugConsensusAPI(engine API) *PublicDebugConsensusAPI {
return &PublicDebugConsensusAPI{engine: engine}
}
// ConsensusStatus returns the status data of the consensus engine.
func (s *PublicDebugConsensusAPI) ConsensusStatus() *Status {
b := s.engine.Status()
var status Status
err := json.Unmarshal(b, &status)
if err == nil {
return &status
}
return nil
}
// GetPrepareQC returns the QC certificate corresponding to the blockNumber.
func (s *PublicDebugConsensusAPI) GetPrepareQC(number uint64) *types.QuorumCert {
return s.engine.GetPrepareQC(number)
}
// PublicPhoenixchainConsensusAPI provides an API to access the PhoenixChain blockchain.
// It offers only methods that operate on public data that
// is freely available to anyone.
type PublicPhoenixchainConsensusAPI struct {
engine API
}
// NewPublicPhoenixchainConsensusAPI creates a new PhoenixChain blockchain API.
func NewPublicPhoenixchainConsensusAPI(engine API) *PublicPhoenixchainConsensusAPI {
return &PublicPhoenixchainConsensusAPI{engine: engine}
}
// Evidences returns the relevant data of the verification.
func (s *PublicPhoenixchainConsensusAPI) Evidences() string {
return s.engine.Evidences()
}
// PublicAdminConsensusAPI provides an API to access the PhoenixChain blockchain.
// It offers only methods that operate on public data that
// is freely available to anyone.
type PublicAdminConsensusAPI struct {
engine API
}
// NewPublicAdminConsensusAPI creates a new PhoenixChain blockchain API.
func NewPublicAdminConsensusAPI(engine API) *PublicAdminConsensusAPI {
return &PublicAdminConsensusAPI{engine: engine}
}
func (s *PublicAdminConsensusAPI) GetSchnorrNIZKProve() string {
proof, err := s.engine.GetSchnorrNIZKProve()
if nil != err {
return err.Error()
}
proofByte, err := proof.MarshalText()
if nil != err {
return err.Error()
}
return string(proofByte)
}