-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from covalenthq/develop
Bsp-agent-DTM-RC:v1.4.9
- Loading branch information
Showing
4 changed files
with
122 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package utils | ||
|
||
import ( | ||
lensp "github.com/covalenthq/lenspath" | ||
"github.com/linkedin/goavro/v2" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var dataLens = createLenspath([]string{"replicaEvent", "*", "data"}) | ||
var transactionsLens = composeLenspath(dataLens, []string{"Transactions", "*"}) | ||
var vLens = composeLenspath(transactionsLens, []string{"v"}) | ||
var rLens = composeLenspath(transactionsLens, []string{"r"}) | ||
var sLens = composeLenspath(transactionsLens, []string{"s"}) | ||
var toLens = composeLenspath(transactionsLens, []string{"to"}) | ||
var fromLens = composeLenspath(transactionsLens, []string{"from"}) | ||
|
||
var headerLens = composeLenspath(dataLens, []string{"Header"}) | ||
var withdrawalsRootLens = composeLenspath(headerLens, []string{"withdrawalsRoot"}) | ||
|
||
var withdrawalsLens = composeLenspath(dataLens, []string{"Withdrawals"}) | ||
var uncleLens = composeLenspath(dataLens, []string{"Uncles"}) | ||
|
||
// utilities for lenspath | ||
|
||
func unwrapType(data map[string]interface{}, lenspath *lensp.Lenspath, nonNilType string) { | ||
lenspathSetter(data, lenspath, func(leafd any) any { | ||
if leafd == nil { | ||
return nil | ||
} | ||
|
||
mp := leafd.(map[string]interface{}) | ||
|
||
return mp[nonNilType] | ||
}) | ||
} | ||
|
||
func wrapType(data map[string]interface{}, lenspath *lensp.Lenspath, nonNilType string) { | ||
lenspathSetter(data, lenspath, func(leafd any) any { | ||
wType := nonNilType | ||
if leafd == nil { | ||
wType = "null" | ||
} | ||
|
||
return goavro.Union(wType, leafd) | ||
}) | ||
} | ||
|
||
func lenspathSetter(data map[string]interface{}, lenspath *lensp.Lenspath, setter func(leafd any) any) { | ||
err := lenspath.Setter(data, setter) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func composeLenspath(prevLenspath *lensp.Lenspath, lens []lensp.Lens) *lensp.Lenspath { | ||
lenspath, err := prevLenspath.Compose(lens) | ||
if err != nil { | ||
log.Fatal(err) | ||
|
||
return nil | ||
} | ||
|
||
return lenspath | ||
} | ||
|
||
func createLenspath(lens []lensp.Lens) *lensp.Lenspath { | ||
lenspath, err := lensp.Create(lens) | ||
if err != nil { | ||
log.Fatal(err) | ||
|
||
return nil | ||
} | ||
|
||
return lenspath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters