A very experimental PLC implementation which uses BFT consensus for decentralization
19
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement ABCI query for validator reputation

gbl08ma ca2f1ec2 59f183f7

+40
+40
abciapp/info.go
··· 2 2 3 3 import ( 4 4 "context" 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 + "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 + "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 + Value: []byte(respJSON), 193 + Code: 0, 194 + }, nil 195 + }, 196 + }, 197 + { 198 + matcher: urlpath.New("/validator/:address/reputation"), 199 + handler: func(match urlpath.Match) (*abcitypes.ResponseQuery, error) { 200 + addressString := match.Params["address"] 201 + addressBytes, err := hex.DecodeString(addressString) 202 + if err != nil || len(addressBytes) != 20 { 203 + return &abcitypes.ResponseQuery{ 204 + Key: []byte(addressString), 205 + Code: 6100, 206 + Log: "Invalid address", 207 + }, nil 208 + } 209 + reputation, err := store.Consensus.ValidatorReputation(readTx, addressBytes) 210 + if err != nil { 211 + return nil, stacktrace.Propagate(err) 212 + } 213 + 214 + resp := struct { 215 + ValidatorAddress string `json:"validatorAddress"` 216 + Reputation string `json:"reputation"` 217 + }{ 218 + ValidatorAddress: hex.EncodeToString(addressBytes), 219 + Reputation: strconv.FormatUint(reputation, 10), 220 + } 221 + 222 + respJSON, err := json.Marshal(&resp) 223 + if err != nil { 224 + return nil, stacktrace.Propagate(err) 225 + } 226 + 227 + return &abcitypes.ResponseQuery{ 228 + Key: []byte(resp.ValidatorAddress), 189 229 Value: []byte(respJSON), 190 230 Code: 0, 191 231 }, nil