tangled
alpha
login
or
join now
gbl08ma.com
/
didplcbft
24
fork
atom
A very experimental PLC implementation which uses BFT consensus for decentralization
24
fork
atom
overview
issues
pulls
pipelines
Implement ABCI query for validator reputation
gbl08ma.com
1 month ago
ca2f1ec2
59f183f7
verified
This commit was signed with the committer's
known signature
.
gbl08ma.com
SSH Key Fingerprint:
SHA256:NkaTDGnGWRZlEnrKxt4ih8fpbNEuHeYdbkJk7VYd+1o=
+40
1 changed file
expand all
collapse all
unified
split
abciapp
info.go
+40
abciapp/info.go
···
2
2
3
3
import (
4
4
"context"
5
5
+
"encoding/hex"
5
6
"encoding/json"
6
7
"errors"
7
8
"fmt"
8
9
"net/http"
9
10
"net/url"
10
11
"runtime"
12
12
+
"strconv"
11
13
"time"
12
14
13
15
abcitypes "github.com/cometbft/cometbft/abci/types"
···
15
17
"github.com/gbl08ma/stacktrace"
16
18
"github.com/ucarion/urlpath"
17
19
"tangled.org/gbl08ma.com/didplcbft/plc"
20
20
+
"tangled.org/gbl08ma.com/didplcbft/store"
18
21
"tangled.org/gbl08ma.com/didplcbft/transaction"
19
22
)
20
23
···
186
189
187
190
return &abcitypes.ResponseQuery{
188
191
Key: []byte(did),
192
192
+
Value: []byte(respJSON),
193
193
+
Code: 0,
194
194
+
}, nil
195
195
+
},
196
196
+
},
197
197
+
{
198
198
+
matcher: urlpath.New("/validator/:address/reputation"),
199
199
+
handler: func(match urlpath.Match) (*abcitypes.ResponseQuery, error) {
200
200
+
addressString := match.Params["address"]
201
201
+
addressBytes, err := hex.DecodeString(addressString)
202
202
+
if err != nil || len(addressBytes) != 20 {
203
203
+
return &abcitypes.ResponseQuery{
204
204
+
Key: []byte(addressString),
205
205
+
Code: 6100,
206
206
+
Log: "Invalid address",
207
207
+
}, nil
208
208
+
}
209
209
+
reputation, err := store.Consensus.ValidatorReputation(readTx, addressBytes)
210
210
+
if err != nil {
211
211
+
return nil, stacktrace.Propagate(err)
212
212
+
}
213
213
+
214
214
+
resp := struct {
215
215
+
ValidatorAddress string `json:"validatorAddress"`
216
216
+
Reputation string `json:"reputation"`
217
217
+
}{
218
218
+
ValidatorAddress: hex.EncodeToString(addressBytes),
219
219
+
Reputation: strconv.FormatUint(reputation, 10),
220
220
+
}
221
221
+
222
222
+
respJSON, err := json.Marshal(&resp)
223
223
+
if err != nil {
224
224
+
return nil, stacktrace.Propagate(err)
225
225
+
}
226
226
+
227
227
+
return &abcitypes.ResponseQuery{
228
228
+
Key: []byte(resp.ValidatorAddress),
189
229
Value: []byte(respJSON),
190
230
Code: 0,
191
231
}, nil