Skip to content

Commit

Permalink
deploy: ec6799a
Browse files Browse the repository at this point in the history
  • Loading branch information
github-merge-queue[bot] committed Nov 15, 2024
1 parent 2c86083 commit daa7fce
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 82 deletions.
60 changes: 20 additions & 40 deletions examples/batch-to-frames.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,12 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
//! Finally, once [Frame]s are built from the [ChannelOut], they are encoded and ready
//! to be batch-submitted to the data availability layer.

use alloy_consensus::{SignableTransaction, TxEip1559};
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{hex, Address, BlockHash, Bytes, PrimitiveSignature, U256};
use brotli::enc::{BrotliCompress, BrotliEncoderParams};
use op_alloy_consensus::OpTxEnvelope;
use op_alloy_genesis::RollupConfig;
use op_alloy_protocol::{Batch, ChannelId, ChannelOut, SingleBatch, CHANNEL_ID_LENGTH};

#[cfg(feature = "std")]
fn main() {
use alloy_primitives::BlockHash;
use op_alloy_genesis::RollupConfig;
use op_alloy_protocol::{Batch, ChannelId, ChannelOut, SingleBatch};

// Use the example transaction
let transactions = example_transactions();

Expand All @@ -347,30 +344,16 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
let epoch_num = 1;
let epoch_hash = BlockHash::ZERO;
let timestamp = 1;

let single_batch = SingleBatch { parent_hash, epoch_num, epoch_hash, timestamp, transactions };
let batch = Batch::Single(single_batch);

// Encode the batch.
let mut encoded = Vec::new();
batch.encode(&amp;mut encoded).unwrap();
let config = RollupConfig::default();
let decoded = Batch::decode(&amp;mut encoded.as_slice(), &amp;config).unwrap();
assert_eq!(batch, decoded);
println!("Encoded Batch: {}", hex::encode(&amp;encoded));

// Compress the encoded batch.
let compressed = compress_brotli(&amp;encoded);
let expected = hex!("1b1301f82f0f6c3734f4821cd090ef3979d71a98e7e483b1dccdd525024c0ef16f425c7b4976a7acc0c94a0514b72c096d4dcc52f0b22dae193c70c86d0790a304a08152c8250031d091063ea0b00d00005082edde7ccf05bded2004462b5e80e1c42cd08e307f5baac723b22864cc6cd01ddde84efc7c018d7ada56c2fa8e3c5bedd494c3a7a884439d5771afcecaf196cb38");
assert_eq!(compressed, expected);
println!("Brotli-compressed batch: {}", hex::encode(&amp;compressed));

// Create a new channel.
let id = random_channel_id();
let id = ChannelId::default();
let config = RollupConfig::default();
let mut channel_out = ChannelOut::new(id, &amp;config);

// Add the compressed batch to the `ChannelOut`.
channel_out.add_raw_compressed_batch(compressed.into());
channel_out.add_batch(batch).unwrap();

// Output frames
while channel_out.ready_bytes() &gt; 0 {
Expand All @@ -382,24 +365,16 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
}

assert!(channel_out.closed);
println!("Successfully encoded Batch to frames");
}

/// Creates a random [ChannelId].
pub fn random_channel_id() -&gt; ChannelId {
let mut id = [0; CHANNEL_ID_LENGTH];
id.iter_mut().for_each(|b| *b = rand::random());
id
}

/// Compresses the given bytes data using the Brotli compressor implemented
/// in the [`brotli`](https://crates.io/crates/brotli) crate.
pub fn compress_brotli(mut input: &amp;[u8]) -&gt; Vec&lt;u8&gt; {
let mut output = vec![];
BrotliCompress(&amp;mut input, &amp;mut output, &amp;BrotliEncoderParams::default()).expect("succeeds");
output
}
#[cfg(feature = "std")]
fn example_transactions() -&gt; Vec&lt;alloy_primitives::Bytes&gt; {
use alloy_consensus::{SignableTransaction, TxEip1559};
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{Address, PrimitiveSignature, U256};
use op_alloy_consensus::OpTxEnvelope;

fn example_transactions() -&gt; Vec&lt;Bytes&gt; {
let mut transactions = Vec::new();

// First Transaction in the batch.
Expand Down Expand Up @@ -445,6 +420,11 @@ <h2 id="running-this-example"><a class="header" href="#running-this-example">Run
assert!(matches!(decoded, OpTxEnvelope::Eip1559(_)));

transactions
}

#[cfg(not(feature = "std"))]
fn main() {
/* not implemented for no_std */
}</code></pre></pre>
<!-- Links -->
<!-- op-alloy -->
Expand Down
60 changes: 20 additions & 40 deletions print.html
Original file line number Diff line number Diff line change
Expand Up @@ -2196,15 +2196,12 @@ <h2 id="running-this-example-1"><a class="header" href="#running-this-example-1"
//! Finally, once [Frame]s are built from the [ChannelOut], they are encoded and ready
//! to be batch-submitted to the data availability layer.

use alloy_consensus::{SignableTransaction, TxEip1559};
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{hex, Address, BlockHash, Bytes, PrimitiveSignature, U256};
use brotli::enc::{BrotliCompress, BrotliEncoderParams};
use op_alloy_consensus::OpTxEnvelope;
use op_alloy_genesis::RollupConfig;
use op_alloy_protocol::{Batch, ChannelId, ChannelOut, SingleBatch, CHANNEL_ID_LENGTH};

#[cfg(feature = "std")]
fn main() {
use alloy_primitives::BlockHash;
use op_alloy_genesis::RollupConfig;
use op_alloy_protocol::{Batch, ChannelId, ChannelOut, SingleBatch};

// Use the example transaction
let transactions = example_transactions();

Expand All @@ -2213,30 +2210,16 @@ <h2 id="running-this-example-1"><a class="header" href="#running-this-example-1"
let epoch_num = 1;
let epoch_hash = BlockHash::ZERO;
let timestamp = 1;

let single_batch = SingleBatch { parent_hash, epoch_num, epoch_hash, timestamp, transactions };
let batch = Batch::Single(single_batch);

// Encode the batch.
let mut encoded = Vec::new();
batch.encode(&amp;mut encoded).unwrap();
let config = RollupConfig::default();
let decoded = Batch::decode(&amp;mut encoded.as_slice(), &amp;config).unwrap();
assert_eq!(batch, decoded);
println!("Encoded Batch: {}", hex::encode(&amp;encoded));

// Compress the encoded batch.
let compressed = compress_brotli(&amp;encoded);
let expected = hex!("1b1301f82f0f6c3734f4821cd090ef3979d71a98e7e483b1dccdd525024c0ef16f425c7b4976a7acc0c94a0514b72c096d4dcc52f0b22dae193c70c86d0790a304a08152c8250031d091063ea0b00d00005082edde7ccf05bded2004462b5e80e1c42cd08e307f5baac723b22864cc6cd01ddde84efc7c018d7ada56c2fa8e3c5bedd494c3a7a884439d5771afcecaf196cb38");
assert_eq!(compressed, expected);
println!("Brotli-compressed batch: {}", hex::encode(&amp;compressed));

// Create a new channel.
let id = random_channel_id();
let id = ChannelId::default();
let config = RollupConfig::default();
let mut channel_out = ChannelOut::new(id, &amp;config);

// Add the compressed batch to the `ChannelOut`.
channel_out.add_raw_compressed_batch(compressed.into());
channel_out.add_batch(batch).unwrap();

// Output frames
while channel_out.ready_bytes() &gt; 0 {
Expand All @@ -2248,24 +2231,16 @@ <h2 id="running-this-example-1"><a class="header" href="#running-this-example-1"
}

assert!(channel_out.closed);
println!("Successfully encoded Batch to frames");
}

/// Creates a random [ChannelId].
pub fn random_channel_id() -&gt; ChannelId {
let mut id = [0; CHANNEL_ID_LENGTH];
id.iter_mut().for_each(|b| *b = rand::random());
id
}

/// Compresses the given bytes data using the Brotli compressor implemented
/// in the [`brotli`](https://crates.io/crates/brotli) crate.
pub fn compress_brotli(mut input: &amp;[u8]) -&gt; Vec&lt;u8&gt; {
let mut output = vec![];
BrotliCompress(&amp;mut input, &amp;mut output, &amp;BrotliEncoderParams::default()).expect("succeeds");
output
}
#[cfg(feature = "std")]
fn example_transactions() -&gt; Vec&lt;alloy_primitives::Bytes&gt; {
use alloy_consensus::{SignableTransaction, TxEip1559};
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{Address, PrimitiveSignature, U256};
use op_alloy_consensus::OpTxEnvelope;

fn example_transactions() -&gt; Vec&lt;Bytes&gt; {
let mut transactions = Vec::new();

// First Transaction in the batch.
Expand Down Expand Up @@ -2311,6 +2286,11 @@ <h2 id="running-this-example-1"><a class="header" href="#running-this-example-1"
assert!(matches!(decoded, OpTxEnvelope::Eip1559(_)));

transactions
}

#[cfg(not(feature = "std"))]
fn main() {
/* not implemented for no_std */
}</code></pre></pre>
<!-- Links -->
<!-- op-alloy -->
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion searchindex.json

Large diffs are not rendered by default.

0 comments on commit daa7fce

Please sign in to comment.