Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions event/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
9 changes: 9 additions & 0 deletions input/chainsync/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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"
}
Expand Down
18 changes: 9 additions & 9 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
}
Expand Down
3 changes: 2 additions & 1 deletion openapi/test/api_default_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 70 additions & 14 deletions output/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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),
},
}

Expand All @@ -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
}
}