remove SignedVAA from /recent response
Change-Id: Idcc7ccfb1bc0ac645dd023d6fff0e51a2e87c84d
This commit is contained in:
parent
d9202dfa08
commit
64078945c4
|
@ -117,8 +117,8 @@ func ReadRow(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
summary := makeSummary(row)
|
||||
jsonBytes, err := json.Marshal(summary)
|
||||
details := makeDetails(row)
|
||||
jsonBytes, err := json.Marshal(details)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
|
|
@ -250,7 +250,21 @@ func Recent(w http.ResponseWriter, r *http.Request) {
|
|||
for k, v := range recent {
|
||||
sort.Slice(v, func(i, j int) bool {
|
||||
// bigtable rows dont have timestamps, use a cell timestamp all rows will have.
|
||||
return v[i]["MessagePublication"][0].Timestamp > v[j]["MessagePublication"][0].Timestamp
|
||||
var iTimestamp bigtable.Timestamp
|
||||
var jTimestamp bigtable.Timestamp
|
||||
// rows may have: only MessagePublication, only QuorumState, or both.
|
||||
// find a timestamp for each row, try to use MessagePublication, if it exists:
|
||||
if len(v[i]["MessagePublication"]) >= 1 {
|
||||
iTimestamp = v[i]["MessagePublication"][0].Timestamp
|
||||
} else if len(v[i]["QuorumState"]) >= 1 {
|
||||
iTimestamp = v[i]["QuorumState"][0].Timestamp
|
||||
}
|
||||
if len(v[j]["MessagePublication"]) >= 1 {
|
||||
jTimestamp = v[j]["MessagePublication"][0].Timestamp
|
||||
} else if len(v[j]["QuorumState"]) >= 1 {
|
||||
jTimestamp = v[j]["QuorumState"][0].Timestamp
|
||||
}
|
||||
return iTimestamp > jTimestamp
|
||||
})
|
||||
// trim the result down to the requested amount now that sorting is complete
|
||||
num := len(v)
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"cloud.google.com/go/bigtable"
|
||||
"github.com/certusone/wormhole/node/pkg/vaa"
|
||||
)
|
||||
|
||||
// shared code for the various functions, primarily response formatting.
|
||||
|
@ -43,14 +43,24 @@ var columnFamilies = []string{"MessagePublication", "Signatures", "VAAState", "Q
|
|||
|
||||
type (
|
||||
Summary struct {
|
||||
EmitterChain string
|
||||
EmitterAddress string
|
||||
Sequence string
|
||||
InitiatingTxID string
|
||||
Payload []byte
|
||||
GuardiansThatSigned []string
|
||||
SignedVAABytes []byte
|
||||
QuorumTime string
|
||||
EmitterChain string
|
||||
EmitterAddress string
|
||||
Sequence string
|
||||
InitiatingTxID string
|
||||
Payload []byte
|
||||
SignedVAABytes []byte
|
||||
QuorumTime string
|
||||
}
|
||||
// Details is a Summary, with the VAA decoded as SignedVAA
|
||||
Details struct {
|
||||
SignedVAA *vaa.VAA
|
||||
EmitterChain string
|
||||
EmitterAddress string
|
||||
Sequence string
|
||||
InitiatingTxID string
|
||||
Payload []byte
|
||||
SignedVAABytes []byte
|
||||
QuorumTime string
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -73,24 +83,32 @@ func makeSummary(row bigtable.Row) *Summary {
|
|||
}
|
||||
}
|
||||
}
|
||||
if _, ok := row[columnFamilies[1]]; ok {
|
||||
for _, item := range row[columnFamilies[1]] {
|
||||
column := strings.Split(item.Column, ":")
|
||||
summary.GuardiansThatSigned = append(summary.GuardiansThatSigned, column[1])
|
||||
}
|
||||
}
|
||||
if _, ok := row[columnFamilies[3]]; ok {
|
||||
|
||||
for _, item := range row[columnFamilies[3]] {
|
||||
if item.Column == "QuorumState:SignedVAA" {
|
||||
summary.SignedVAABytes = item.Value
|
||||
summary.QuorumTime = item.Timestamp.Time().String()
|
||||
}
|
||||
}
|
||||
item := row[columnFamilies[3]][0]
|
||||
summary.SignedVAABytes = item.Value
|
||||
summary.QuorumTime = item.Timestamp.Time().String()
|
||||
}
|
||||
return summary
|
||||
}
|
||||
|
||||
func makeDetails(row bigtable.Row) *Details {
|
||||
sum := makeSummary(row)
|
||||
deets := &Details{
|
||||
EmitterChain: sum.EmitterChain,
|
||||
EmitterAddress: sum.EmitterAddress,
|
||||
Sequence: sum.Sequence,
|
||||
InitiatingTxID: sum.InitiatingTxID,
|
||||
Payload: sum.Payload,
|
||||
SignedVAABytes: sum.SignedVAABytes,
|
||||
QuorumTime: sum.QuorumTime,
|
||||
}
|
||||
if _, ok := row[columnFamilies[3]]; ok {
|
||||
item := row[columnFamilies[3]][0]
|
||||
deets.SignedVAA, _ = vaa.Unmarshal(item.Value)
|
||||
}
|
||||
return deets
|
||||
}
|
||||
|
||||
var mux = newMux()
|
||||
|
||||
// Entry is the cloud function entry point
|
||||
|
|
|
@ -99,8 +99,8 @@ func Transaction(w http.ResponseWriter, r *http.Request) {
|
|||
log.Fatalf("Could not read row with key %s: %v", key, err)
|
||||
}
|
||||
|
||||
summary := makeSummary(row)
|
||||
jsonBytes, err := json.Marshal(summary)
|
||||
details := makeDetails(row)
|
||||
jsonBytes, err := json.Marshal(details)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
|
Loading…
Reference in New Issue