-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: download csv of omiga_inscription transactions (#1571)
Signed-off-by: Miles Zhang <[email protected]>
- Loading branch information
1 parent
9b711fb
commit 0919c22
Showing
4 changed files
with
160 additions
and
1 deletion.
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
78 changes: 78 additions & 0 deletions
78
app/jobs/csv_exportable/export_omiga_inscription_transactions_job.rb
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,78 @@ | ||
module CsvExportable | ||
class ExportOmigaInscriptionTransactionsJob < BaseExporter | ||
def perform(args) | ||
udt = Udt.find_by!(type_hash: args[:id], published: true) | ||
ckb_transactions = udt.ckb_transactions | ||
|
||
if args[:start_date].present? | ||
start_date = BigDecimal(args[:start_date]) | ||
ckb_transactions = ckb_transactions.where("block_timestamp >= ?", | ||
start_date) | ||
end | ||
|
||
if args[:end_date].present? | ||
end_date = BigDecimal(args[:end_date]) | ||
ckb_transactions = ckb_transactions.where("block_timestamp <= ?", | ||
end_date) | ||
end | ||
|
||
if args[:start_number].present? | ||
ckb_transactions = ckb_transactions.where("block_number >= ?", | ||
args[:start_number]) | ||
end | ||
|
||
if args[:end_number].present? | ||
ckb_transactions = ckb_transactions.where("block_number <= ?", | ||
args[:end_number]) | ||
end | ||
|
||
ckb_transactions = ckb_transactions.includes(:inputs, :outputs). | ||
order(block_timestamp: :desc).limit(5000) | ||
|
||
rows = [] | ||
ckb_transactions.find_in_batches(batch_size: 1000, | ||
order: :desc) do |transactions| | ||
transactions.each do |transaction| | ||
row = generate_row(transaction, udt) | ||
next if row.blank? | ||
|
||
rows << row | ||
end | ||
end | ||
|
||
header = [ | ||
"Txn hash", "Blockno", "UnixTimestamp", "Method", "Token", | ||
"Amount", "date(UTC)" | ||
] | ||
|
||
generate_csv(header, rows) | ||
end | ||
|
||
def generate_row(transaction, udt) | ||
inputs = transaction.inputs.omiga_inscription | ||
outputs = transaction.outputs.omiga_inscription | ||
|
||
datetime = datetime_utc(transaction.block_timestamp) | ||
unit = udt.symbol.presence || udt.name | ||
method = | ||
if inputs.blank? && outputs.present? | ||
"mint" | ||
elsif inputs.present? && outputs.present? | ||
"rebase_mint" | ||
else | ||
"unknown" | ||
end | ||
data = CkbUtils.parse_omiga_inscription_data(outputs.first.data) | ||
|
||
[ | ||
transaction.tx_hash, | ||
transaction.block_number, | ||
transaction.block_timestamp, | ||
method, | ||
unit, | ||
data[:mint_limit], | ||
datetime, | ||
] | ||
end | ||
end | ||
end |
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