From b4592a3b757546e4d63647a1c8f2536f093d59f8 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Wed, 25 Oct 2023 12:56:23 -0400 Subject: [PATCH] feat: wire up issuer verification key Signed-off-by: Chris Gianelloni --- go.mod | 4 ++-- go.sum | 4 ++-- input/chainsync/block.go | 15 +++------------ input/chainsync/tx.go | 10 +++++----- output/webhook/webhook.go | 13 ++++--------- 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index ee22b66..d16188e 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,7 @@ module github.com/blinklabs-io/snek go 1.20 require ( - github.com/blinklabs-io/gouroboros v0.57.0 - github.com/fxamacker/cbor/v2 v2.5.0 + github.com/blinklabs-io/gouroboros v0.58.0 github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd github.com/gin-gonic/gin v1.9.1 github.com/kelseyhightower/envconfig v1.4.0 @@ -28,6 +27,7 @@ require ( github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect github.com/chenzhuoyu/iasm v0.9.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fxamacker/cbor/v2 v2.5.0 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/jsonpointer v0.20.0 // indirect diff --git a/go.sum b/go.sum index e994527..772305d 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGB cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= -github.com/blinklabs-io/gouroboros v0.57.0 h1:k5Y706vvYAGM3bCtEhh6WRHGrvS3S6n1MT9vNLFAe/E= -github.com/blinklabs-io/gouroboros v0.57.0/go.mod h1:D5YJka8EyVmiXNMbRvjH23H9lNMLA4+qSlNNC/j7R0k= +github.com/blinklabs-io/gouroboros v0.58.0 h1:W1/fjntOfJ3Yn41/SjgxV4cS7XSuogCZYznygRXUj8Q= +github.com/blinklabs-io/gouroboros v0.58.0/go.mod h1:D5YJka8EyVmiXNMbRvjH23H9lNMLA4+qSlNNC/j7R0k= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= diff --git a/input/chainsync/block.go b/input/chainsync/block.go index 27c486e..729bd0b 100644 --- a/input/chainsync/block.go +++ b/input/chainsync/block.go @@ -15,15 +15,12 @@ package chainsync import ( - "fmt" - "github.com/blinklabs-io/gouroboros/ledger" - "github.com/fxamacker/cbor/v2" ) type BlockContext struct { - BlockNumber uint64 `json:"blockNumber"` - SlotNumber uint64 `json:"slotNumber"` + BlockNumber uint64 `json:"blockNumber"` + SlotNumber uint64 `json:"slotNumber"` } type BlockEvent struct { @@ -50,16 +47,10 @@ func NewBlockHeaderContext(block ledger.BlockHeader) BlockContext { } func NewBlockEvent(block ledger.Block, includeCbor bool) BlockEvent { - keyCbor, err := cbor.Marshal(block.IssuerVkey()) - if err != nil { - panic(err) - } - // iss := ledger.NewBlake2b256(block.IssuerVkey()) evt := BlockEvent{ BlockBodySize: block.BlockBodySize(), BlockHash: block.Hash(), - IssuerVkey: fmt.Sprintf("%x", keyCbor), - // IssuerVkey: iss.String(), + IssuerVkey: block.IssuerVkey().Hash().String(), } if includeCbor { evt.BlockCbor = block.Cbor() diff --git a/input/chainsync/tx.go b/input/chainsync/tx.go index d530fda..152bac9 100644 --- a/input/chainsync/tx.go +++ b/input/chainsync/tx.go @@ -48,11 +48,11 @@ func NewTransactionContext(block ledger.Block, tx ledger.Transaction, index uint func NewTransactionEvent(block ledger.Block, tx ledger.Transaction, includeCbor bool) TransactionEvent { evt := TransactionEvent{ - BlockHash: block.Hash(), - Inputs: tx.Inputs(), - Outputs: tx.Outputs(), - Fee: tx.Fee(), - TTL: tx.TTL(), + BlockHash: block.Hash(), + Inputs: tx.Inputs(), + Outputs: tx.Outputs(), + Fee: tx.Fee(), + TTL: tx.TTL(), } if includeCbor { evt.TransactionCbor = tx.Cbor() diff --git a/output/webhook/webhook.go b/output/webhook/webhook.go index 1570a74..b31b7be 100644 --- a/output/webhook/webhook.go +++ b/output/webhook/webhook.go @@ -118,10 +118,6 @@ func formatWebhook(e *event.Event, format string) []byte { case "chainsync.block": be := e.Payload.(chainsync.BlockEvent) bc := e.Context.(chainsync.BlockContext) - // keyCbor, err := cbor.Marshal(be.IssuerVkey) - // if err != nil { - // panic(err) - // } dme.Title = "New Cardano Block" dmefs = append(dmefs, &DiscordMessageEmbedField{ Name: "Block Number", @@ -135,11 +131,10 @@ func formatWebhook(e *event.Event, format string) []byte { Name: "Block Hash", Value: be.BlockHash, }) - // TODO: get the pool identifier from be.IssuerVkey - // dmefs = append(dmefs, &DiscordMessageEmbedField{ - // Name: "Issuer Vkey", - // Value: fmt.Sprintf("%x", keyCbor), - // }) + dmefs = append(dmefs, &DiscordMessageEmbedField{ + Name: "Issuer Vkey", + Value: be.IssuerVkey, + }) // TODO: fix this URL for different networks dme.URL = fmt.Sprintf("https://cexplorer.io/block/%s", be.BlockHash) case "chainsync.rollback":