Skip to main content
This document outlines methods to extract required fields from the XDR of raw data. Use Cases:
  • Backfix for a bugfix
  • Backfix for a new column added
  • Temporary extraction of fields not parsed by stellar-etl
We’ll take the example of extracting the 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:
This process will generate the following file in the js-stellar-base/dist/ directory:
  • 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):
This script will output the 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:
This query will update the fee_account_muxed field in the crypto_stellar.history_transactions table using values calculated from the UDF.

Conclusion

By following these steps, you can effectively extract and manipulate XDR data fields in BigQuery using JavaScript UDFs, making it easier to process and analyze your Stellar network data. You can also apply bugfix for existing dataset.