Skip to content

Commit 71751e4

Browse files
authored
added balances and signatures to OverflowTransaction (#175)
1 parent d4521ff commit 71751e4

File tree

5 files changed

+71
-60
lines changed

5 files changed

+71
-60
lines changed

event.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ type OverflowEvent struct {
5252
EventIndex uint32 `json:"eventIndex"`
5353
}
5454

55+
type FeeBalance struct {
56+
PayerBalance float64 `json:"payerBalance"`
57+
TotalFeeBalance float64 `json:"totalFeeBalance"`
58+
}
59+
5560
// Check if an event exist in the other events
5661
func (o OverflowEvent) ExistIn(events []OverflowEvent) bool {
5762
for _, ev := range events {
@@ -231,8 +236,10 @@ func (overflowEvents OverflowEvents) FilterTempWithdrawDeposit() OverflowEvents
231236
var feeReceipients = []string{"0xf919ee77447b7497", "0x912d5440f7e3769e", "0xe5a8b7f23e8b548f", "0xab086ce9cc29fc80"}
232237

233238
// Filtter out fee events
234-
func (overflowEvents OverflowEvents) FilterFees(fee float64, payer string) OverflowEvents {
239+
func (overflowEvents OverflowEvents) FilterFees(fee float64, payer string) (OverflowEvents, FeeBalance) {
235240
filteredEvents := overflowEvents
241+
242+
fees := FeeBalance{}
236243
for name, events := range overflowEvents {
237244
if strings.HasSuffix(name, "FlowFees.FeesDeducted") {
238245
delete(filteredEvents, name)
@@ -250,6 +257,8 @@ func (overflowEvents OverflowEvents) FilterFees(fee float64, payer string) Overf
250257
from, ok := value.Fields["from"].(string)
251258

252259
if ok && amount == fee && from == payer {
260+
balance, _ := value.Fields["balanceAfter"].(float64)
261+
fees.PayerBalance = balance
253262
continue
254263
}
255264

@@ -274,6 +283,8 @@ func (overflowEvents OverflowEvents) FilterFees(fee float64, payer string) Overf
274283
to, ok := value.Fields["to"].(string)
275284

276285
if ok && amount == fee && slices.Contains(feeReceipients, to) {
286+
balance, _ := value.Fields["balanceAfter"].(float64)
287+
fees.TotalFeeBalance = balance
277288
continue
278289
}
279290
depositEvents = append(depositEvents, value)
@@ -326,7 +337,7 @@ func (overflowEvents OverflowEvents) FilterFees(fee float64, payer string) Overf
326337

327338
}
328339
}
329-
return filteredEvents
340+
return filteredEvents, fees
330341
}
331342

332343
func printOrLog(t *testing.T, s string) {

event_filter_test.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,23 @@ import (
88
)
99

1010
func TestFilterOverflowEvents(t *testing.T) {
11-
1211
events := OverflowEvents{
13-
"A.123.Test.Deposit": []OverflowEvent{{Fields: map[string]interface{}{
14-
"id": 1,
15-
"string": "string",
16-
}},
12+
"A.123.Test.Deposit": []OverflowEvent{
13+
{Fields: map[string]interface{}{
14+
"id": 1,
15+
"string": "string",
16+
}},
1717
},
1818
}
1919

2020
t.Run("Filter out all events should yield empty", func(t *testing.T) {
21-
2221
filter := OverflowEventFilter{
2322
"Deposit": []string{"id", "string"},
2423
}
2524
filtered := events.FilterEvents(filter)
2625
assert.Empty(t, filtered)
27-
2826
})
2927
t.Run("Filter out single field", func(t *testing.T) {
30-
3128
filter := OverflowEventFilter{
3229
"Deposit": []string{"id"},
3330
}
@@ -39,7 +36,6 @@ func TestFilterOverflowEvents(t *testing.T) {
3936
})
4037

4138
t.Run("Filter fees", func(t *testing.T) {
42-
4339
eventsWithFees := OverflowEvents{
4440
"A.f919ee77447b7497.FlowFees.FeesDeducted": []OverflowEvent{
4541
{Fields: map[string]interface{}{
@@ -64,7 +60,7 @@ func TestFilterOverflowEvents(t *testing.T) {
6460
}},
6561
},
6662
}
67-
filtered := eventsWithFees.FilterFees(0.00000918, "0x55ad22f01ef568a1")
63+
filtered, _ := eventsWithFees.FilterFees(0.00000918, "0x55ad22f01ef568a1")
6864
want := autogold.Want("fees filtered", OverflowEvents{"A.1654653399040a61.FlowToken.TokensDeposited": []OverflowEvent{
6965
{Fields: map[string]interface{}{
7066
"amount": 1,
@@ -75,7 +71,6 @@ func TestFilterOverflowEvents(t *testing.T) {
7571
})
7672

7773
t.Run("Filter fees with other transfer", func(t *testing.T) {
78-
7974
eventsWithFees := OverflowEvents{
8075
"A.f919ee77447b7497.FlowFees.FeesDeducted": []OverflowEvent{{Fields: map[string]interface{}{
8176
"amount": 0.00000918,
@@ -97,7 +92,7 @@ func TestFilterOverflowEvents(t *testing.T) {
9792
"to": "0xf919ee77447b7497",
9893
}}},
9994
}
100-
filtered := eventsWithFees.FilterFees(0.00000918, "0x55ad22f01ef568a1")
95+
filtered, _ := eventsWithFees.FilterFees(0.00000918, "0x55ad22f01ef568a1")
10196
want := autogold.Want("fees filtered with transfer", OverflowEvents{
10297
"A.1654653399040a61.FlowToken.TokensDeposited": []OverflowEvent{
10398
{Fields: map[string]interface{}{
@@ -114,7 +109,6 @@ func TestFilterOverflowEvents(t *testing.T) {
114109
})
115110

116111
t.Run("Filter empty deposit withdraw", func(t *testing.T) {
117-
118112
eventsWithFees := OverflowEvents{
119113
"A.1654653399040a61.FlowToken.TokensWithdrawn": []OverflowEvent{{Fields: map[string]interface{}{
120114
"amount": 0.00000918,
@@ -139,7 +133,6 @@ func TestFilterOverflowEvents(t *testing.T) {
139133
})
140134

141135
t.Run("Filter non-empty deposit withdraw", func(t *testing.T) {
142-
143136
eventsWithFees := OverflowEvents{
144137
"A.1654653399040a61.FlowToken.TokensWithdrawn": []OverflowEvent{{Fields: map[string]interface{}{
145138
"amount": 0.00000918,
@@ -174,7 +167,6 @@ func TestFilterOverflowEvents(t *testing.T) {
174167
})
175168

176169
t.Run("Filter all empty deposit withdraw", func(t *testing.T) {
177-
178170
eventsWithFees := OverflowEvents{
179171
"A.1654653399040a61.FlowToken.TokensWithdrawn": []OverflowEvent{{Fields: map[string]interface{}{
180172
"amount": 0.00000918,
@@ -189,5 +181,4 @@ func TestFilterOverflowEvents(t *testing.T) {
189181
want := autogold.Want("filter all empty deposit withdraw", OverflowEvents{})
190182
want.Equal(t, filtered)
191183
})
192-
193184
}

interaction_builder.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,13 @@ func (oib OverflowInteractionBuilder) Send() *OverflowResult {
612612
result.FeeGas = gas
613613
}
614614

615-
if !oib.IgnoreGlobalEventFilters {
616-
617-
fee := result.Fee["amount"]
615+
feeAmount := result.Fee["amount"]
616+
eventsWithoutFees, feeFromEvents := overflowEvents.FilterFees(feeAmount.(float64), fmt.Sprintf("0x%s", result.Transaction.Payer.Hex()))
617+
result.Balance = feeFromEvents
618618

619-
if oib.Overflow.FilterOutFeeEvents && fee != nil {
620-
overflowEvents = overflowEvents.FilterFees(fee.(float64), fmt.Sprintf("0x%s", result.Transaction.Payer.Hex()))
619+
if !oib.IgnoreGlobalEventFilters {
620+
if oib.Overflow.FilterOutFeeEvents && feeAmount != nil {
621+
overflowEvents = eventsWithoutFees
621622
}
622623
if oib.Overflow.FilterOutEmptyWithDrawDepositEvents {
623624
overflowEvents = overflowEvents.FilterTempWithdrawDeposit()

result.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type OverflowResult struct {
5858
Fee map[string]interface{}
5959
FeeGas int
6060

61+
Balance FeeBalance
6162
// The name of the Transaction
6263
Name string
6364

transaction.go

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,27 @@ type Argument struct {
2121
}
2222

2323
type OverflowTransaction struct {
24-
Error error
25-
AuthorizerTypes map[string][]string
26-
Stakeholders map[string][]string
27-
Payer string
28-
Id string
29-
Status string
30-
BlockId string
31-
Authorizers []string
32-
Arguments []Argument
33-
Events []OverflowEvent
34-
Imports []Import
35-
Script []byte
36-
ProposalKey flow.ProposalKey
37-
Fee float64
38-
TransactionIndex int
39-
GasLimit uint64
40-
GasUsed uint64
41-
ExecutionEffort float64
24+
Error error
25+
AuthorizerTypes map[string][]string
26+
Stakeholders map[string][]string
27+
Payer string
28+
Id string
29+
Status string
30+
BlockId string
31+
Authorizers []string
32+
Arguments []Argument
33+
Events []OverflowEvent
34+
Imports []Import
35+
Script []byte
36+
ProposalKey flow.ProposalKey
37+
Fee float64
38+
TransactionIndex int
39+
GasLimit uint64
40+
GasUsed uint64
41+
ExecutionEffort float64
42+
Balances FeeBalance
43+
PayloadSignatures []flow.TransactionSignature
44+
EnvelopeSignatures []flow.TransactionSignature
4245
}
4346

4447
func (o *OverflowState) CreateOverflowTransaction(blockId string, transactionResult flow.TransactionResult, transaction flow.Transaction, txIndex int) (*OverflowTransaction, error) {
@@ -115,32 +118,36 @@ func (o *OverflowState) CreateOverflowTransaction(blockId string, transactionRes
115118
standardStakeholders[fmt.Sprintf("0x%s", transaction.ProposalKey.Address.Hex())] = proposer
116119
}
117120

118-
eventsWithoutFees := events.FilterFees(feeAmount, fmt.Sprintf("0x%s", transaction.Payer.Hex()))
121+
// TODO: here we need to get out the balance of the payer and the fee recipient
122+
eventsWithoutFees, balanceFees := events.FilterFees(feeAmount, fmt.Sprintf("0x%s", transaction.Payer.Hex()))
119123

120124
eventList := []OverflowEvent{}
121125
for _, evList := range eventsWithoutFees {
122126
eventList = append(eventList, evList...)
123127
}
124128

125129
return &OverflowTransaction{
126-
Id: transactionResult.TransactionID.String(),
127-
TransactionIndex: txIndex,
128-
BlockId: blockId,
129-
Status: status,
130-
Events: eventList,
131-
Stakeholders: eventsWithoutFees.GetStakeholders(standardStakeholders),
132-
Imports: imports,
133-
Error: transactionResult.Error,
134-
Arguments: args,
135-
Fee: feeAmount,
136-
Script: transaction.Script,
137-
Payer: fmt.Sprintf("0x%s", transaction.Payer.String()),
138-
ProposalKey: transaction.ProposalKey,
139-
GasLimit: transaction.GasLimit,
140-
GasUsed: uint64(gas),
141-
ExecutionEffort: executionEffort,
142-
Authorizers: authorizers,
143-
AuthorizerTypes: authorizerTypes,
130+
Id: transactionResult.TransactionID.String(),
131+
TransactionIndex: txIndex,
132+
BlockId: blockId,
133+
Status: status,
134+
Events: eventList,
135+
Stakeholders: eventsWithoutFees.GetStakeholders(standardStakeholders),
136+
Imports: imports,
137+
Error: transactionResult.Error,
138+
Arguments: args,
139+
Fee: feeAmount,
140+
Script: transaction.Script,
141+
Payer: fmt.Sprintf("0x%s", transaction.Payer.String()),
142+
ProposalKey: transaction.ProposalKey,
143+
GasLimit: transaction.GasLimit,
144+
GasUsed: uint64(gas),
145+
ExecutionEffort: executionEffort,
146+
Authorizers: authorizers,
147+
AuthorizerTypes: authorizerTypes,
148+
Balances: balanceFees,
149+
PayloadSignatures: transaction.PayloadSignatures,
150+
EnvelopeSignatures: transaction.EnvelopeSignatures,
144151
}, nil
145152
}
146153

0 commit comments

Comments
 (0)