- Backfix for a bugfix
- Backfix for a new column added
- Temporary extraction of fields not parsed by stellar-etl
fee_account_muxed field from a transaction envelope (tx_meta XDR). However, this method can be adapted to other fields as well. It is worth noting that most users will not need to standup and run their own Hubble. The Stellar Development Foundation provides public access to the data through the public datasets and tables in GCP BigQuery. Instructions on how to access this data can be found in the Connecting section.
We will use the js-stellar-base library to parse the XDR and employ JavaScript UDFs (User Defined Functions) in BigQuery to apply the transformation to the dataset.
For a deeper understanding, check out the Medium article on using NPM libraries in Google BigQuery UDFs.
Step 1: Setting Up JS UDF in BigQuery
To set up the JS UDF in BigQuery, follow these steps:1. Clone the js-stellar-base repository
First, clone the repository to your local machine and install the dependencies:
- stellar-base.min.js
2. Upload the JS file to Google Cloud Storage (GCS)
Once the build process is completed, upload the stellar-base.min.js file to a Google Cloud Storage bucket to be used in the UDF.Step 2: Writing the JavaScript Function
Here is an example JavaScript function to extract the fee_account_muxed field from the transaction envelope (tx_meta):fee_account_muxed value: MBX64B6V7KV2KVHJ66IIKLNEIKCHF5BI57BNMF3U6RJIUHNBMXSJEAAACYGGCDRL6UFO2
Step 3: Wrapping the JavaScript Function as a UDF
Sample Output for the JS UDF
After running the above query, you should receive output similar to the following:Step 4: Updating Column Values Using UDF
You can also use this UDF to update values in a BigQuery table. Here’s an example of how to do this:fee_account_muxed field in the crypto_stellar.history_transactions table using values calculated from the UDF.