Crate arloader[][src]

Expand description

SDK for uploading files in bulk to Arweave.

CLI

See README.md for usage instructions.

The main cli application is all in main a follows a pattern of specifying arguments, matching them, and then in turn passing them to commands, which are all broken out separately in the commands module to facilitate re-use in other command line applications or as library functions.

Library

Overview

The library is mostly focused on uploading files as efficiently as possible. Arweave has two different transaction formats and two different upload formats. Transactions can either be normal, single data item transactions (see transaction format for details), or bundle transactions (see bundle format for details). The bundle format, introduced mid-2021, bundles together individual data items into larger transactions, making uploading much more efficient and reducing network congestion. The library supports both formats, with the recommended approach being to use the bundle format.

There are also two upload formats, whole transactions, which if they are less than 12 MB get uploaded to the tx/ endpoint, and chunks, which get uploaded in 256 KB chunks to the chunk/endpoint. Arloader includes functions for both.

Transactions and DataItems

Both transaction formats start with chunking file data and creating merkle trees from the chunks. The merkle tree logic can be found in the merkle module. All of the hashing functions and other crypto operations are in the crypto module. Once the data is chunked, hashed, and a merkle root calculated for it, it gets incorporated into either a Transaction, which can be found in the transaction module, or a DataItem (if it is going to be included in a bundle format transaction), which can be found in the bundle module.

Tags

Tags are structs with name and value properties that can be included with either Transactions or DataItems. One subtlety is that for Transactions, Arweave expects the content at each key to be a base64 url encoded string, whereas for DataItems, Arweave expects utf8-encoded strings. Tags have been implemented for Arloader includes implementations for both as, Tag<Base64> and Tag<String>.

A Tag with a name property of Content-Type is used by the Arweave gateways to communicate the mime type of the related content to browsers. Arloader creates the appropriate content type type from a a mime-type database based on file extension if one is provided, otherwise from magic numbers based on the content bytes.

Bytes and Base64Url Data

The library stores all data, signatures and addresses as a Base64 struct with implementations for serialization and deserialization that automatically convert the underlying bytes to and from the Base64Url format required for submission to Arweave.

Signing

A key part of constructing transactions is signing them. Arweave has a specific algorithm for generating the digest that gets signed and then hashed to serve as a transaction id, called deep hash. It takes various elements of either the Transaction or DataItem, including nested arrays of Tags, and successively hashes and concatenates and them together. The required elements are assembled using the ToItems trait, implemented separately for Transaction::to_deep_hash_item and DataItem::to_deep_hash_item. Arloader’s implementation of the deep hash algorithm can be found in crypto::Provider::deep_hash.

Higher Level Functions

The functions for creating Transactions, DataItems and bundles are all consolidated on the Arweave struct. In general, there are lower level functions for creating single items from data, that are then used in successively higher level functions to create multiple items from collections of file paths, ultimately uploading streams of items to Arweave.

Status Tracking

The library includes additional functionality to track and report on transaction statuses. There are two status structs, Status and BundleStatus used for these purposes. They are essentially the same format, except that BundleStatus is modified to include references to all of the included DataItems instead of just a single Transaction for Status.

Solana

The functions for allowing payment to be made in SOL can be found in the solana module.

Modules

Data structure and functionality to create, serialize and deserialize DataItems.

Functions for Cli commands composed from library functions.

Functionality for creating and verifying signatures and hashing.

Errors propagated by library functions.

Functionality for chunking file data and calculating and verifying root ids.

Includes functionality for paying for transaction in SOL.

Data structures for reporting transaction statuses.

Data structures for serializing and deserializing Transactions and Tags.

Async TempDir for testing.

Structs

Struct with methods for interacting with the Arweave network.

Tuple struct includes two elements: chunk of paths and aggregatge data size of paths.

Constants

Block size used for pricing calculations = 256 KB

Winstons are a sub unit of the native Arweave network token, AR. There are 1012 Winstons per AR.

Functions

Used when updating to determine wether files in a directory are BundleStatuss.

Queries network and updates locally stored BundleStatus structs.

Queries network and updates locally stored Status structs.

Uploads a stream of bundles from Vec<PathsChunk>s.

Uploads a stream of bundles from Vec<PathsChunk>s, paying with SOL.

Uploads files matching glob pattern, returning a stream of Status structs.

Uploads files matching glob pattern, returning a stream of Status structs, paying with SOL.