stellar / go

Stellar's public monorepo of go code
https://stellar.org/developers
Apache License 2.0
1.3k stars 499 forks source link

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

Open chowbao opened 1 month ago

chowbao commented 1 month ago

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:

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: https://github.com/stellar/go/issues/5476 blocks: https://github.com/stellar/go/issues/5477, https://stellarorg.atlassian.net/browse/HUBBLE-231

chowbao commented 3 days ago

Design/one pager for the low level helper functions (XDRill) https://github.com/stellar/platform-design-docs/pull/2