Skip to content

Commit

Permalink
Adds --nfts to chifra export
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Feb 18, 2025
1 parent a4f8c19 commit 75819da
Show file tree
Hide file tree
Showing 87 changed files with 935 additions and 386 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.0
4.3.0
14 changes: 13 additions & 1 deletion docs/content/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ info:
license:
name: GPL 3.0
url: http://www.gnu.org/licenses/
version: 4.2.0-release
version: 4.3.0-release
description: >
A REST layer over the TrueBlocks chifra command line. With `chifra daemon`, you can
run this on your own machine, and make calls to `localhost`.
Expand Down Expand Up @@ -420,6 +420,14 @@ paths:
items:
type: string
format: topic
- name: nfts
description: for the --logs option only, filter logs to show only nft transfers
required: false
style: form
in: query
explode: true
schema:
type: boolean
- name: reverted
description: export only transactions that were reverted
required: false
Expand Down Expand Up @@ -3666,6 +3674,10 @@ components:
type: string
format: string
description: "a truncated, more readable version of the articulation (calculated)"
isNFT:
type: boolean
format: boolean
description: "true if the log is an NFT transfer"
trace:
description: "trace data as returned from the RPC (with slight enhancements)"
type: object
Expand Down
1 change: 1 addition & 0 deletions docs/content/chifra/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Flags:
-N, --relevant for log and accounting export only, export only logs relevant to one of the given export addresses
-m, --emitter strings for the --logs option only, filter logs to show only those logs emitted by the given address(es)
-B, --topic strings for the --logs option only, filter logs to show only those with this topic(s)
-T, --nfts for the --logs option only, filter logs to show only nft transfers
-V, --reverted export only transactions that were reverted
-P, --asset strings for the accounting options only, export statements only for this asset
-f, --flow string for the accounting options only, export statements with incoming, outgoing, or zero value
Expand Down
1 change: 1 addition & 0 deletions docs/content/data-model/chaindata.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Logs consist of the following fields:
| blockHash | the hash of the block | hash |
| articulatedLog | a human-readable version of the topic and data fields | [Function](/data-model/other/#function) |
| compressedLog | a truncated, more readable version of the articulation (calculated) | string |
| isNFT | true if the log is an NFT transfer | bool |

## Trace

Expand Down
2 changes: 1 addition & 1 deletion sdk
1 change: 1 addition & 0 deletions src/apps/chifra/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func init() {
exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Relevant, "relevant", "N", false, `for log and accounting export only, export only logs relevant to one of the given export addresses`)
exportCmd.Flags().StringSliceVarP(&exportPkg.GetOptions().Emitter, "emitter", "m", nil, `for the --logs option only, filter logs to show only those logs emitted by the given address(es)`)
exportCmd.Flags().StringSliceVarP(&exportPkg.GetOptions().Topic, "topic", "B", nil, `for the --logs option only, filter logs to show only those with this topic(s)`)
exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Nfts, "nfts", "T", false, `for the --logs option only, filter logs to show only nft transfers`)
exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Reverted, "reverted", "V", false, `export only transactions that were reverted`)
exportCmd.Flags().StringSliceVarP(&exportPkg.GetOptions().Asset, "asset", "P", nil, `for the accounting options only, export statements only for this asset`)
exportCmd.Flags().StringVarP(&exportPkg.GetOptions().Flow, "flow", "f", "", `for the accounting options only, export statements with incoming, outgoing, or zero value
Expand Down
1 change: 1 addition & 0 deletions src/apps/chifra/internal/export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Flags:
-N, --relevant for log and accounting export only, export only logs relevant to one of the given export addresses
-m, --emitter strings for the --logs option only, filter logs to show only those logs emitted by the given address(es)
-B, --topic strings for the --logs option only, filter logs to show only those with this topic(s)
-T, --nfts for the --logs option only, filter logs to show only nft transfers
-V, --reverted export only transactions that were reverted
-P, --asset strings for the accounting options only, export statements only for this asset
-f, --flow string for the accounting options only, export statements with incoming, outgoing, or zero value
Expand Down
7 changes: 4 additions & 3 deletions src/apps/chifra/internal/export/handle_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ func (opts *ExportOptions) HandleLogs(rCtx *output.RenderCtx, monitorArray []mon
})

for _, item := range items {
var passes bool
passes, finished = filter.ApplyCountFilter()
if passes {
var passes1, passes2 bool
passes1, finished = filter.ApplyCountFilter()
passes2 = !opts.Nfts || item.IsNFT
if passes1 && passes2 {
modelChan <- item
}
if finished {
Expand Down
4 changes: 4 additions & 0 deletions src/apps/chifra/internal/export/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type ExportOptions struct {
Relevant bool `json:"relevant,omitempty"` // For log and accounting export only, export only logs relevant to one of the given export addresses
Emitter []string `json:"emitter,omitempty"` // For the --logs option only, filter logs to show only those logs emitted by the given address(es)
Topic []string `json:"topic,omitempty"` // For the --logs option only, filter logs to show only those with this topic(s)
Nfts bool `json:"nfts,omitempty"` // For the --logs option only, filter logs to show only nft transfers
Reverted bool `json:"reverted,omitempty"` // Export only transactions that were reverted
Asset []string `json:"asset,omitempty"` // For the accounting options only, export statements only for this asset
Flow string `json:"flow,omitempty"` // For the accounting options only, export statements with incoming, outgoing, or zero value
Expand Down Expand Up @@ -91,6 +92,7 @@ func (opts *ExportOptions) testLog() {
logger.TestLog(opts.Relevant, "Relevant: ", opts.Relevant)
logger.TestLog(len(opts.Emitter) > 0, "Emitter: ", opts.Emitter)
logger.TestLog(len(opts.Topic) > 0, "Topic: ", opts.Topic)
logger.TestLog(opts.Nfts, "Nfts: ", opts.Nfts)
logger.TestLog(opts.Reverted, "Reverted: ", opts.Reverted)
logger.TestLog(len(opts.Asset) > 0, "Asset: ", opts.Asset)
logger.TestLog(len(opts.Flow) > 0, "Flow: ", opts.Flow)
Expand Down Expand Up @@ -182,6 +184,8 @@ func ExportFinishParseInternal(w io.Writer, values url.Values) *ExportOptions {
s := strings.Split(val, " ") // may contain space separated items
opts.Topic = append(opts.Topic, s...)
}
case "nfts":
opts.Nfts = true
case "reverted":
opts.Reverted = true
case "asset":
Expand Down
4 changes: 4 additions & 0 deletions src/apps/chifra/internal/export/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ func (opts *ExportOptions) validateExport() error {
return validate.Usage("Invalid topic: {0}", t)
}
}

} else {
if opts.Nfts {
return validate.Usage("The {0} option is only available with the {1} option.", "--nfts", "--logs")
}
if len(opts.Emitter) > 0 {
return validate.Usage("The {0} option is only available with the {1} option.", "--emitter", "--logs")
}
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/pkg/articulate/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ func findCommonEvent(log *types.Log) (*types.Function, error) {
return nil, nil
}

if normalized, _, err := normalize.NormalizeKnownLogs(log); err != nil {
if normalized, isNFT, err := normalize.NormalizeKnownLogs(log); err != nil {
return nil, err

} else {
log.IsNFT = isNFT
switch normalized.Topics[0] {
case topics.TransferTopic:
return parseTransferEvent(normalized), nil
Expand Down
23 changes: 23 additions & 0 deletions src/apps/chifra/pkg/types/types_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Log struct {
BlockHash base.Hash `json:"blockHash"`
BlockNumber base.Blknum `json:"blockNumber"`
Data string `json:"data,omitempty"`
IsNFT bool `json:"isNFT,omitempty"`
LogIndex base.Lognum `json:"logIndex"`
Timestamp base.Timestamp `json:"timestamp,omitempty"`
Topics []base.Hash `json:"topics,omitempty"`
Expand Down Expand Up @@ -74,6 +75,7 @@ func (s *Log) Model(chain, format string, verbose bool, extraOpts map[string]any
"topic2",
"topic3",
"data",
"isNFT",
}

isArticulated := extraOpts["articulate"] == true && s.ArticulatedLog != nil
Expand All @@ -87,16 +89,23 @@ func (s *Log) Model(chain, format string, verbose bool, extraOpts map[string]any
}

if format == "json" {
if s.IsNFT {
model["isNFT"] = s.IsNFT
}

if len(s.Data) > 2 {
model["data"] = s.Data
}

if isArticulated {
model["articulatedLog"] = articulatedLog
}

model["topics"] = s.Topics

} else {
model["isNFT"] = s.IsNFT

if len(s.Data) > 2 {
model["data"] = s.Data
} else {
Expand Down Expand Up @@ -200,6 +209,11 @@ func (s *Log) MarshalCache(writer io.Writer) (err error) {
return err
}

// IsNFT
if err = cache.WriteValue(writer, s.IsNFT); err != nil {
return err
}

// LogIndex
if err = cache.WriteValue(writer, s.LogIndex); err != nil {
return err
Expand Down Expand Up @@ -271,6 +285,15 @@ func (s *Log) UnmarshalCache(vers uint64, reader io.Reader) (err error) {
return err
}

// IsNFT
vIsNFT := version.NewVersion("4.2.0")
if vers > vIsNFT.Uint64() {
// IsNFT
if err = cache.ReadValue(reader, &s.IsNFT, vers); err != nil {
return err
}
}

// LogIndex
if err = cache.ReadValue(reader, &s.LogIndex, vers); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/pkg/types/types_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type Statement struct {
MinerNephewRewardIn base.Wei `json:"minerNephewRewardIn,omitempty"`
MinerTxFeeIn base.Wei `json:"minerTxFeeIn,omitempty"`
MinerUncleRewardIn base.Wei `json:"minerUncleRewardIn,omitempty"`
PostFirst bool `json:"postFirst"`
PostLast bool `json:"postLast"`
PostFirst bool `json:"postFirst,omitempty"`
PostLast bool `json:"postLast,omitempty"`
PrefundIn base.Wei `json:"prefundIn,omitempty"`
PrevBal base.Wei `json:"prevBal,omitempty"`
PriceSource string `json:"priceSource"`
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/version/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

package version

const LibraryVersion = "GHC-TrueBlocks//4.2.0-release"
const LibraryVersion = "GHC-TrueBlocks//4.3.0-release"
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ transactionHash ,hash , , , , 9 ,th
blockHash ,hash , , , , 10 ,the hash of the block
articulatedLog ,*Function , ,omitempty , , 11 ,a human-readable version of the topic and data fields
compressedLog ,string , ,calc ,2.5.10:string , 12 ,a truncated&#44; more readable version of the articulation
isNFT ,bool , ,omitempty ,>4.2.0:bool , 13 ,true if the log is an NFT transfer
1 change: 1 addition & 0 deletions src/dev_tools/goMaker/templates/cmd-line-options.csv
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,handler,option_ty
13190,apps,Accounts,export,acctExport,relevant,N,,visible|docs,,switch,<boolean>,,,,,for log and accounting export only&#44; export only logs relevant to one of the given export addresses
13200,apps,Accounts,export,acctExport,emitter,m,,visible|docs,,flag,list<addr>,,,,,for the --logs option only&#44; filter logs to show only those logs emitted by the given address(es)
13210,apps,Accounts,export,acctExport,topic,B,,visible|docs,,flag,list<topic>,,,,,for the --logs option only&#44; filter logs to show only those with this topic(s)
13215,apps,Accounts,export,acctExport,nfts,T,,visible|docs,,switch,<boolean>,,,,,for the --logs option only&#44; filter logs to show only nft transfers
13220,apps,Accounts,export,acctExport,reverted,V,,visible|docs,,switch,<boolean>,,,,,export only transactions that were reverted
13230,apps,Accounts,export,acctExport,asset,P,,visible|docs,,flag,list<addr>,,,,,for the accounting options only&#44; export statements only for this asset
13240,apps,Accounts,export,acctExport,flow,f,,visible|docs,,flag,enum[in|out|zero],,,,,for the accounting options only&#44; export statements with incoming&#44; outgoing&#44; or zero value
Expand Down
2 changes: 2 additions & 0 deletions src/dev_tools/sdkFuzzer/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func DoExport() {
relevant := []bool{false, true}
emitter := fuzzEmitters
topic := fuzzTopics
nfts := []bool{false, true}
reverted := []bool{false, true}
asset := fuzzAssets
// Option 'flow.enum' is an emum
Expand All @@ -52,6 +53,7 @@ func DoExport() {
_ = topic
_ = fourbytes
_ = articulate
_ = nfts
baseFn := "export/export"
opts = sdk.ExportOptions{
Addrs: fuzzAddresses,
Expand Down
8 changes: 6 additions & 2 deletions src/dev_tools/testRunner/testCases/export.csv
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ on ,both ,fast ,export ,apps ,acctExport ,export_logs_topics_10 ,n
on ,both ,fast ,export ,apps ,acctExport ,export_logs_topics_3 ,n ,addrs = 0x111111517e4929d3dcbdfa7cce55d30d4b6bc4d6 & logs & topic = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef & max_records = 3 & fmt = csv
on ,both ,fast ,export ,apps ,acctExport ,export_logs_topics_fb_3 ,n ,addrs = 0x111111517e4929d3dcbdfa7cce55d30d4b6bc4d6 & logs & topic = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef & first_block = 14353374 & max_records = 3 & fmt = csv

on ,both ,fast ,export ,apps ,acctExport ,not_nfts ,y ,addrs = trueblocks.eth & logs & articulate & first_block = 8876230 & last_block = 9024186 & fmt = json
on ,both ,fast ,export ,apps ,acctExport ,nfts ,y ,addrs = trueblocks.eth & logs & articulate & nfts & first_block = 8876230 & last_block = 9024186 & fmt = json
on ,both ,fast ,export ,apps ,acctExport ,nfts_fail ,y ,addrs = trueblocks.eth & nfts & articulate & first_block = 8876230 & last_block = 9024186 & fmt = json

# Testing adding a fourbyte value
on ,both ,fast ,export ,apps ,acctExport ,invalid_fourbyte ,y ,addrs = 0xf503017d7baf7fbc0fff7492b751025c6a78179b & fourbytes = 0xa9059c & max_records = 10 & fmt = json
on ,both ,fast ,export ,apps ,acctExport ,invalid_fourbyte_2 ,y ,addrs = 0xf503017d7baf7fbc0fff7492b751025c6a78179b & fourbytes = 0xa9059c & logs & max_records = 10 & fmt = json
Expand All @@ -95,8 +99,8 @@ on ,both ,fast ,export ,apps ,acctExport ,simple_prefund2 ,y
on ,both ,fast ,export ,apps ,acctExport ,reverted ,n ,addrs = 0xf503017d7baf7fbc0fff7492b751025c6a78179b & reverted & max_records = 2 & fmt = txt
on ,both ,fast ,export ,apps ,acctExport ,reverted_fourbytes ,n ,addrs = 0xf503017d7baf7fbc0fff7492b751025c6a78179b & reverted & fourbytes = 0xab832b43 & max_records = 2 & fmt = txt

on ,both ,fast ,export ,apps ,acctExport ,not_withdrawals ,y ,addrs = 0x6193f68d97921f4765d72a3e6964fc990c59e0e5 & first_block = 17013606 & last_block = 17083530 & fmt = json
on ,both ,fast ,export ,apps ,acctExport ,withdrawals ,y ,addrs = 0x6193f68d97921f4765d72a3e6964fc990c59e0e5 & withdrawals & first_block = 17013606 & last_block = 17083530 & fmt = json
with ,both ,fast ,export ,apps ,acctExport ,not_withdrawals ,y ,addrs = 0x6193f68d97921f4765d72a3e6964fc990c59e0e5 & first_block = 17013606 & last_block = 17083530 & fmt = json
with ,both ,fast ,export ,apps ,acctExport ,withdrawals ,y ,addrs = 0x6193f68d97921f4765d72a3e6964fc990c59e0e5 & withdrawals & first_block = 17013606 & last_block = 17083530 & fmt = json
on ,both ,fast ,export ,apps ,acctExport ,withdrawals_fail ,y ,addrs = chasewright.eth & withdrawals & logs & first_block = 17048500 & last_block = 17139600 & fmt = json

on ,both ,fast ,export ,apps ,acctExport ,invalid_key ,y ,addrs = 0xf503017d7baf7fbc0fff7492b751025c6a78179b & first_block = 10277780 & last_block = 10296792 & fmt = json & from
Expand Down
1 change: 1 addition & 0 deletions tests/gold/apps/acctExport/acctExport_accounting_ofx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Flags:
-N, --relevant for log and accounting export only, export only logs relevant to one of the given export addresses
-m, --emitter strings for the --logs option only, filter logs to show only those logs emitted by the given address(es)
-B, --topic strings for the --logs option only, filter logs to show only those with this topic(s)
-T, --nfts for the --logs option only, filter logs to show only nft transfers
-V, --reverted export only transactions that were reverted
-P, --asset strings for the accounting options only, export statements only for this asset
-f, --flow string for the accounting options only, export statements with incoming, outgoing, or zero value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Flags:
-N, --relevant for log and accounting export only, export only logs relevant to one of the given export addresses
-m, --emitter strings for the --logs option only, filter logs to show only those logs emitted by the given address(es)
-B, --topic strings for the --logs option only, filter logs to show only those with this topic(s)
-T, --nfts for the --logs option only, filter logs to show only nft transfers
-V, --reverted export only transactions that were reverted
-P, --asset strings for the accounting options only, export statements only for this asset
-f, --flow string for the accounting options only, export statements with incoming, outgoing, or zero value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Flags:
-N, --relevant for log and accounting export only, export only logs relevant to one of the given export addresses
-m, --emitter strings for the --logs option only, filter logs to show only those logs emitted by the given address(es)
-B, --topic strings for the --logs option only, filter logs to show only those with this topic(s)
-T, --nfts for the --logs option only, filter logs to show only nft transfers
-V, --reverted export only transactions that were reverted
-P, --asset strings for the accounting options only, export statements only for this asset
-f, --flow string for the accounting options only, export statements with incoming, outgoing, or zero value
Expand Down
1 change: 1 addition & 0 deletions tests/gold/apps/acctExport/acctExport_caps_allowed_e.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Flags:
-N, --relevant for log and accounting export only, export only logs relevant to one of the given export addresses
-m, --emitter strings for the --logs option only, filter logs to show only those logs emitted by the given address(es)
-B, --topic strings for the --logs option only, filter logs to show only those with this topic(s)
-T, --nfts for the --logs option only, filter logs to show only nft transfers
-V, --reverted export only transactions that were reverted
-P, --asset strings for the accounting options only, export statements only for this asset
-f, --flow string for the accounting options only, export statements with incoming, outgoing, or zero value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Flags:
-N, --relevant for log and accounting export only, export only logs relevant to one of the given export addresses
-m, --emitter strings for the --logs option only, filter logs to show only those logs emitted by the given address(es)
-B, --topic strings for the --logs option only, filter logs to show only those with this topic(s)
-T, --nfts for the --logs option only, filter logs to show only nft transfers
-V, --reverted export only transactions that were reverted
-P, --asset strings for the accounting options only, export statements only for this asset
-f, --flow string for the accounting options only, export statements with incoming, outgoing, or zero value
Expand Down
Loading

0 comments on commit 75819da

Please sign in to comment.