Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ingest/cdp: Create low level helper functions for pulling out specific fields in LCM #5475

Open
chowbao opened this issue Sep 25, 2024 · 0 comments

Comments

@chowbao
Copy link
Contributor

chowbao commented Sep 25, 2024

As part of the CDP processor design/brainstorm, we all agreed that there's benefit in creating low level helper functions that users can call to get the specific field/data for their needs.

There is a draft PR that relates to the low level helper functions. Note: placed randomly in stellar-etl for convenience

Things to decide/discuss:

  • Where should these helper functions live? New package, ingest, go/xdr?
  • Which fields should we target first? (keep initial scope low but enough to be useful)
    • Ideally we could have functions for every field/data
    • Even if we only target ledgers, transactions, and operations the number of fields is still quite large
    • Is it possible to leverage XDR <> JSON functions at all to help this?
  • Should we define a standard interface/template for these low level helper functions?
  • Should we return go data types or the xdr types like xdr.Uint32?
    • I'd lean go types
  • What should happen if there are similarly named fields?
    • Low code function to return account - which account (buyer/seller)

Examples and cases to consider:
Simple case: easy traversing through LCM and returning a simple type

func BaseFee(lcm xdr.LedgerCloseMeta) (uint32, error) {
	ledgerHeader := lcm.LedgerHeaderHistoryEntry()
	baseFee := ledgerHeader.Header.BaseFee
	return uint32(baseFee), nil
}

Cases with V# xdr structs

func SorobanFeeWrite1Kb(lcm xdr.LedgerCloseMeta) (int64, error) {
	switch lcm.V {
	case 0:
		return nil, nil
	case 1:
		lcmV1Ext := lcm.MustV1().Ext
		switch lcmV1Ext.V {
		case 0:
			return nil, nil
		case 1:
			ext := lcmV1Ext.MustV1()
			sorobanFreeWrite1Kb := ext.SorobanFeeWrite1Kb
			return int64(sorobanFreeWrite1Kb), nil
		default:
			panic(fmt.Errorf("unsupported LedgerCloseMeta.V1.Ext.V: %d", lcmV1Ext.V))
		}
	default:
		panic(fmt.Errorf("unsupported LedgerCloseMeta.V: %d", lcm.V))
	}
}

Cases where the return type could be more subjective like with xdr.ScVal

relates to: #5476
blocks: #5477, https://stellarorg.atlassian.net/browse/HUBBLE-231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To Do
Development

No branches or pull requests

1 participant