diff --git a/docs/docs.go b/docs/docs.go index f6494e2..98046d0 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,5 +1,6 @@ -// Code generated by swaggo/swag. DO NOT EDIT. - +// Package docs +// +// Code generated by swaggo/swag. DO NOT EDIT package docs import "github.com/swaggo/swag" @@ -171,6 +172,8 @@ var SwaggerInfo = &swag.Spec{ Description: "Adder API", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/event/tx.go b/event/tx.go index e4b0a98..179786c 100644 --- a/event/tx.go +++ b/event/tx.go @@ -15,7 +15,6 @@ package event import ( - "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger" lcommon "github.com/blinklabs-io/gouroboros/ledger/common" ) @@ -32,7 +31,7 @@ type TransactionEvent struct { Transaction ledger.Transaction `json:"-"` Witnesses lcommon.TransactionWitnessSet `json:"witnesses,omitempty"` Withdrawals map[string]uint64 `json:"withdrawals,omitempty"` - Metadata *cbor.LazyValue `json:"metadata,omitempty"` + Metadata lcommon.TransactionMetadatum `json:"metadata,omitempty"` BlockHash string `json:"blockHash"` ReferenceInputs []ledger.TransactionInput `json:"referenceInputs,omitempty"` Certificates []ledger.Certificate `json:"certificates,omitempty"` diff --git a/go.mod b/go.mod index 55b1149..820567e 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ toolchain go1.24.4 require ( github.com/SundaeSwap-finance/kugo v1.3.0 github.com/SundaeSwap-finance/ogmigo/v6 v6.2.0 - github.com/blinklabs-io/gouroboros v0.140.0 - github.com/blinklabs-io/plutigo v0.0.14 + github.com/blinklabs-io/gouroboros v0.142.0 + github.com/blinklabs-io/plutigo v0.0.16 github.com/btcsuite/btcd/btcutil v1.1.6 github.com/gen2brain/beeep v0.11.1 github.com/gin-gonic/gin v1.11.0 diff --git a/go.sum b/go.sum index 4ca1164..f1a59b0 100644 --- a/go.sum +++ b/go.sum @@ -17,12 +17,12 @@ github.com/aws/aws-sdk-go v1.55.6 h1:cSg4pvZ3m8dgYcgqB97MrcdjUmZ1BeMYKUxMMB89IPk github.com/aws/aws-sdk-go v1.55.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/bits-and-blooms/bitset v1.20.0 h1:2F+rfL86jE2d/bmw7OhqUg2Sj/1rURkBn3MdfoPyRVU= github.com/bits-and-blooms/bitset v1.20.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= -github.com/blinklabs-io/gouroboros v0.140.0 h1:dFK2iunkTflCI2hlDSGZJJ7JerYhpdE41HnBUVvjj9E= -github.com/blinklabs-io/gouroboros v0.140.0/go.mod h1:FxKQNNNRQN5F/Cl4pnW7SHhpPo7fD57mTPGo4N9ulnY= -github.com/blinklabs-io/ouroboros-mock v0.3.9 h1:UnciDccJ5tZCR1xI0BcxGZcYjJ/PS5MpnjiiGtrZ680= -github.com/blinklabs-io/ouroboros-mock v0.3.9/go.mod h1:uTkE8/LAYL7yQSntH48Pudf5Xn+jaBWMj+9udbzYXhI= -github.com/blinklabs-io/plutigo v0.0.14 h1:K45/tQpZwJFdCcrhigepbdSPQG/+0pp99cCrbJdSl44= -github.com/blinklabs-io/plutigo v0.0.14/go.mod h1:W4TnQiGhc6da5G+jXAW3O/Q/tgqG9QoITRJ1FCXd260= +github.com/blinklabs-io/gouroboros v0.142.0 h1:vBsQfcPsZF7EX+1uw1Gcg0uCYvkjsEVHn2qEqlMC0lY= +github.com/blinklabs-io/gouroboros v0.142.0/go.mod h1:pC42tYVwkd34ohGrWAIHhLOWhhpmrBa0M/QUE+4gC8Q= +github.com/blinklabs-io/ouroboros-mock v0.4.0 h1:ppOcTMnC/2f5rYYSlvNqcGfAQOIpMCSDUrNh9K6a4mY= +github.com/blinklabs-io/ouroboros-mock v0.4.0/go.mod h1:e+Kck8bmdOuaN7IfkbVvbqAVlskXNXB95oHI3YlFG5g= +github.com/blinklabs-io/plutigo v0.0.16 h1:3+1eOby9ckoDXb+8ObCBQ4BGbHZ6z7cxGFDR4cbS+7Y= +github.com/blinklabs-io/plutigo v0.0.16/go.mod h1:aT3mJAh1s8JJ8C42ygd8OyGDQZ8f+w8Uge2+C/9BLug= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A= diff --git a/input/chainsync/block_test.go b/input/chainsync/block_test.go index 41b64a2..dc5b8f8 100644 --- a/input/chainsync/block_test.go +++ b/input/chainsync/block_test.go @@ -31,6 +31,7 @@ type MockBlockHeader struct { hash common.Blake2b256 prevHash common.Blake2b256 issuerVkey common.IssuerVkey + blockBodyHash common.Blake2b256 } func (m MockBlockHeader) Hash() common.Blake2b256 { @@ -65,6 +66,10 @@ func (m MockBlockHeader) Cbor() []byte { return m.cborBytes } +func (m MockBlockHeader) BlockBodyHash() common.Blake2b256 { + return m.blockBodyHash +} + // MockBlock implements Block interface type MockBlock struct { MockBlockHeader @@ -87,6 +92,10 @@ func (m MockBlock) Utxorpc() (*utxorpc.Block, error) { return nil, nil } +func (m MockBlock) BlockBodyHash() common.Blake2b256 { + return m.MockBlockHeader.BlockBodyHash() +} + func (m MockBlock) IsShelley() bool { return m.era.Name == "Shelley" } diff --git a/internal/config/config.go b/internal/config/config.go index ebe36b5..b8368a7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -73,16 +73,16 @@ const ( ) type Config struct { - ByronGenesis ByronGenesisConfig `yaml:"byron_genesis" envconfig:"BYRON_GENESIS"` - Plugin map[string]map[string]map[any]any `yaml:"plugins" envconfig:"PLUGINS"` - Logging LoggingConfig `yaml:"logging" envconfig:"LOGGING"` + ByronGenesis ByronGenesisConfig `yaml:"byron_genesis" envconfig:"BYRON_GENESIS"` + Plugin map[string]map[string]map[any]any `yaml:"plugins" envconfig:"PLUGINS"` + Logging LoggingConfig `yaml:"logging" envconfig:"LOGGING"` ConfigFile string `yaml:"-"` - Input string `yaml:"input" envconfig:"INPUT"` - Output string `yaml:"output" envconfig:"OUTPUT"` - KupoUrl string `yaml:"kupo_url" envconfig:"KUPO_URL"` - Api ApiConfig `yaml:"api" envconfig:"API"` - Debug DebugConfig `yaml:"debug" envconfig:"DEBUG"` - ShelleyGenesis ShelleyGenesisConfig `yaml:"shelley_genesis" envconfig:"SHELLEY_GENESIS"` + Input string `yaml:"input" envconfig:"INPUT"` + Output string `yaml:"output" envconfig:"OUTPUT"` + KupoUrl string `yaml:"kupo_url" envconfig:"KUPO_URL"` + Api ApiConfig `yaml:"api" envconfig:"API"` + Debug DebugConfig `yaml:"debug" envconfig:"DEBUG"` + ShelleyGenesis ShelleyGenesisConfig `yaml:"shelley_genesis" envconfig:"SHELLEY_GENESIS"` ShelleyTransEpoch int32 `yaml:"shelley_trans_epoch" envconfig:"SHELLEY_TRANS_EPOCH"` Version bool `yaml:"-"` } diff --git a/openapi/test/api_default_test.go b/openapi/test/api_default_test.go index 6081fe0..d9ba0a5 100644 --- a/openapi/test/api_default_test.go +++ b/openapi/test/api_default_test.go @@ -11,10 +11,11 @@ package openapi import ( "context" + "testing" + openapiclient "github.com/blinklabs-io/cardano-node-api/openapi" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_DefaultAPIService(t *testing.T) { diff --git a/output/push/push.go b/output/push/push.go index 7897310..f906dc2 100644 --- a/output/push/push.go +++ b/output/push/push.go @@ -16,16 +16,18 @@ package push import ( "context" + "encoding/hex" "encoding/json" "errors" "fmt" + "math/big" "os" "github.com/blinklabs-io/adder/event" "github.com/blinklabs-io/adder/internal/logging" "github.com/blinklabs-io/adder/output/push/fcm" "github.com/blinklabs-io/adder/plugin" - "github.com/blinklabs-io/gouroboros/cbor" + "github.com/blinklabs-io/gouroboros/ledger/common" "golang.org/x/oauth2/google" ) @@ -306,40 +308,54 @@ func (p *PushOutput) OutputChan() <-chan event.Event { // This should probably go in gouroboros module // extractCIP20FromMetadata extracts the CIP20 message from the transaction metadata // and returns it as a JSON string. -func extractCIP20FromMetadata(metadata *cbor.LazyValue) (string, error) { +func extractCIP20FromMetadata( + metadata common.TransactionMetadatum, +) (string, error) { if metadata == nil { return "", errors.New("metadata is nil") } - if _, err := metadata.Decode(); err != nil { - return "", fmt.Errorf("could not decode metadata: %w", err) - } - - metadataMap, ok := metadata.Value().(map[any]any) + metaMap, ok := metadata.(common.MetaMap) if !ok { - return "", errors.New("metadata value is not of the expected map type") + return "", errors.New("metadata is not a MetaMap") } - // Extract the nested value for key 674 - nestedValue, found := metadataMap[uint64(674)] + var nestedValue common.TransactionMetadatum + found := false + for _, pair := range metaMap.Pairs { + if keyInt, ok := pair.Key.(common.MetaInt); ok && + keyInt.Value.Cmp(big.NewInt(674)) == 0 { + nestedValue = pair.Value + found = true + break + } + } if !found { return "", errors.New("key 674 not found in metadata") } - // Assert the nested value is a map - nestedMap, ok := nestedValue.(map[any]any) + nestedMap, ok := nestedValue.(common.MetaMap) if !ok { return "", errors.New("nested value for key 674 is not a map") } - msgValue, found := nestedMap["msg"] + var msgValue common.TransactionMetadatum + found = false + for _, pair := range nestedMap.Pairs { + if keyText, ok := pair.Key.(common.MetaText); ok && + keyText.Value == "msg" { + msgValue = pair.Value + found = true + break + } + } if !found { return "", errors.New("key 'msg' not found in nested metadata map") } msgStruct := map[string]any{ "674": map[string]any{ - "msg": msgValue, + "msg": metadatumToAny(msgValue), }, } @@ -350,3 +366,43 @@ func extractCIP20FromMetadata(metadata *cbor.LazyValue) (string, error) { return string(jsonBytes), nil } + +func keyToString(md common.TransactionMetadatum) string { + switch v := md.(type) { + case common.MetaInt: + return v.Value.String() + case common.MetaBytes: + return hex.EncodeToString(v.Value) + case common.MetaText: + return v.Value + default: + return fmt.Sprintf("%v", metadatumToAny(md)) + } +} + +func metadatumToAny(md common.TransactionMetadatum) any { + switch v := md.(type) { + case common.MetaInt: + return v.Value + case common.MetaBytes: + return v.Value + case common.MetaText: + return v.Value + case common.MetaList: + var list []any + for _, item := range v.Items { + list = append(list, metadatumToAny(item)) + } + return list + case common.MetaMap: + m := make(map[string]any) + for _, pair := range v.Pairs { + keyStr := keyToString(pair.Key) + value := metadatumToAny(pair.Value) + m[keyStr] = value + } + return m + default: + return nil + } +}