Skip to content

Commit

Permalink
added methods to interface that we need exposed
Browse files Browse the repository at this point in the history
  • Loading branch information
bjartek committed Mar 14, 2024
1 parent 76bdff7 commit ead0871
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 5 deletions.
6 changes: 5 additions & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ func (e OverflowEvent) MarshalAs(marshalTo interface{}) error {
return nil
}

func (o *OverflowState) ParseEvents(events []flow.Event, idPrefix string) (OverflowEvents, OverflowEvent) {
func (o *OverflowState) ParseEvents(events []flow.Event) (OverflowEvents, OverflowEvent) {
return o.ParseEventsWithIdPrefix(events, "")
}

func (o *OverflowState) ParseEventsWithIdPrefix(events []flow.Event, idPrefix string) (OverflowEvents, OverflowEvent) {
overflowEvents := OverflowEvents{}
fee := OverflowEvent{}
for i, event := range events {
Expand Down
2 changes: 1 addition & 1 deletion interaction_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func (oib OverflowInteractionBuilder) Send() *OverflowResult {

result.RawEvents = res.Events

overflowEvents, fee := oib.Overflow.ParseEvents(result.RawEvents, "")
overflowEvents, fee := oib.Overflow.ParseEvents(result.RawEvents)
result.Fee = fee.Fields
if len(result.Fee) != 0 {
executionEffort, ok := result.Fee["executionEffort"].(float64)
Expand Down
246 changes: 246 additions & 0 deletions mocks/OverflowClient.go

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

11 changes: 10 additions & 1 deletion state.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ type OverflowClient interface {
GetOverflowTransactionById(ctx context.Context, id flow.Identifier) (*OverflowTransaction, error)

// NB! This will contain system chunk transactions on mainnet/testnet
GetTransactionByBlockId(ctx context.Context, id flow.Identifier) ([]*flow.Transaction, []*flow.TransactionResult, error)
GetTransactionsByBlockId(ctx context.Context, id flow.Identifier) ([]*flow.Transaction, []*flow.TransactionResult, error)

// parse flow events into overflow events, the last argument is the fee event, the id prefix is there for system chunk events since the id it generates must be unique
ParseEvents(events []flow.Event) (OverflowEvents, OverflowEvent)

// this method can be used to parse events emitted from system chunk transactions with a prefix
ParseEventsWithIdPrefix(events []flow.Event, idPrefix string) (OverflowEvents, OverflowEvent)

// use this method to transform a flow transactionResult and transaction into a overflow transaction
CreateOverflowTransaction(blockId string, transactionResult flow.TransactionResult, transaction flow.Transaction, txIndex int) (*OverflowTransaction, error)
}

var _ OverflowClient = (*OverflowState)(nil)
Expand Down
4 changes: 2 additions & 2 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type OverflowTransaction struct {

func (o *OverflowState) CreateOverflowTransaction(blockId string, transactionResult flow.TransactionResult, transaction flow.Transaction, txIndex int) (*OverflowTransaction, error) {
feeAmount := 0.0
events, fee := o.ParseEvents(transactionResult.Events, "")
events, fee := o.ParseEvents(transactionResult.Events)
feeRaw, ok := fee.Fields["amount"]
if ok {
feeAmount, ok = feeRaw.(float64)
Expand Down Expand Up @@ -161,7 +161,7 @@ func (o *OverflowState) GetTransactionById(ctx context.Context, id flow.Identifi
return tx, nil
}

func (o *OverflowState) GetTransactionByBlockId(ctx context.Context, id flow.Identifier) ([]*flow.Transaction, []*flow.TransactionResult, error) {
func (o *OverflowState) GetTransactionsByBlockId(ctx context.Context, id flow.Identifier) ([]*flow.Transaction, []*flow.TransactionResult, error) {
tx, txr, err := o.Flowkit.GetTransactionsByBlockID(ctx, id)
if err != nil {
return nil, nil, err
Expand Down

0 comments on commit ead0871

Please sign in to comment.