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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
summary := makeSummary(row)
|
details := makeDetails(row)
|
||||||
jsonBytes, err := json.Marshal(summary)
|
jsonBytes, err := json.Marshal(details)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
|
|
|
@ -250,7 +250,21 @@ func Recent(w http.ResponseWriter, r *http.Request) {
|
||||||
for k, v := range recent {
|
for k, v := range recent {
|
||||||
sort.Slice(v, func(i, j int) bool {
|
sort.Slice(v, func(i, j int) bool {
|
||||||
// bigtable rows dont have timestamps, use a cell timestamp all rows will have.
|
// 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
|
// trim the result down to the requested amount now that sorting is complete
|
||||||
num := len(v)
|
num := len(v)
|
||||||
|
|
|
@ -5,10 +5,10 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"cloud.google.com/go/bigtable"
|
"cloud.google.com/go/bigtable"
|
||||||
|
"github.com/certusone/wormhole/node/pkg/vaa"
|
||||||
)
|
)
|
||||||
|
|
||||||
// shared code for the various functions, primarily response formatting.
|
// shared code for the various functions, primarily response formatting.
|
||||||
|
@ -43,14 +43,24 @@ var columnFamilies = []string{"MessagePublication", "Signatures", "VAAState", "Q
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Summary struct {
|
Summary struct {
|
||||||
EmitterChain string
|
EmitterChain string
|
||||||
EmitterAddress string
|
EmitterAddress string
|
||||||
Sequence string
|
Sequence string
|
||||||
InitiatingTxID string
|
InitiatingTxID string
|
||||||
Payload []byte
|
Payload []byte
|
||||||
GuardiansThatSigned []string
|
SignedVAABytes []byte
|
||||||
SignedVAABytes []byte
|
QuorumTime string
|
||||||
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 {
|
if _, ok := row[columnFamilies[3]]; ok {
|
||||||
|
item := row[columnFamilies[3]][0]
|
||||||
for _, item := range row[columnFamilies[3]] {
|
summary.SignedVAABytes = item.Value
|
||||||
if item.Column == "QuorumState:SignedVAA" {
|
summary.QuorumTime = item.Timestamp.Time().String()
|
||||||
summary.SignedVAABytes = item.Value
|
|
||||||
summary.QuorumTime = item.Timestamp.Time().String()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return summary
|
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()
|
var mux = newMux()
|
||||||
|
|
||||||
// Entry is the cloud function entry point
|
// 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)
|
log.Fatalf("Could not read row with key %s: %v", key, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
summary := makeSummary(row)
|
details := makeDetails(row)
|
||||||
jsonBytes, err := json.Marshal(summary)
|
jsonBytes, err := json.Marshal(details)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
|
|
Loading…
Reference in New Issue