Skip to content

Commit

Permalink
Merge pull request #24 from nervina-labs/develop
Browse files Browse the repository at this point in the history
Release v0.7.0
  • Loading branch information
duanyytop authored Nov 1, 2022
2 parents 0044dea + 4d5c66f commit d67ea75
Show file tree
Hide file tree
Showing 9 changed files with 1,673 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2021-12-25
toolchain: nightly-2022-08-01
override: true

- uses: docker-practice/actions-setup-docker@master
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "cota-smt"
version = "0.5.0"
version = "0.7.0"
edition = "2018"

[dependencies]
cfg-if = "1.0"
blake2b-ref = "0.3"
blake2b-ref = "0.3.1"
ckb-std = {version = "0.9.0", optional = true}
ckb-types = {version = "0.101.1", optional = true}
molecule = {version = "0.7.2", default_features = false, optional = true}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2021-12-25
nightly-2022-08-01
1 change: 1 addition & 0 deletions src/common.mol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
array Uint16 [byte; 2];
array Uint32 [byte; 4];
array Uint64 [byte; 8];
array Byte6 [byte; 6];
array Byte32 [byte; 32];

array CotaId [byte; 20];
Expand Down
273 changes: 273 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern crate alloc;
pub use alloc::vec::*;
// these lines above are manually added

use molecule::prelude::*;
#[derive(Clone)]
pub struct Uint16(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for Uint16 {
Expand Down Expand Up @@ -752,6 +753,278 @@ impl molecule::prelude::Builder for Uint64Builder {
}
}
#[derive(Clone)]
pub struct Byte6(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for Byte6 {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for Byte6 {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for Byte6 {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
let raw_data = hex_string(&self.raw_data());
write!(f, "{}(0x{})", Self::NAME, raw_data)
}
}
impl ::core::default::Default for Byte6 {
fn default() -> Self {
let v: Vec<u8> = vec![0, 0, 0, 0, 0, 0];
Byte6::new_unchecked(v.into())
}
}
impl Byte6 {
pub const ITEM_COUNT: usize = 6;
pub const ITEM_SIZE: usize = 1;
pub const TOTAL_SIZE: usize = 6;

pub fn nth0(&self) -> Byte {
Byte::new_unchecked(self.0.slice(0..1))
}

pub fn nth1(&self) -> Byte {
Byte::new_unchecked(self.0.slice(1..2))
}

pub fn nth2(&self) -> Byte {
Byte::new_unchecked(self.0.slice(2..3))
}

pub fn nth3(&self) -> Byte {
Byte::new_unchecked(self.0.slice(3..4))
}

pub fn nth4(&self) -> Byte {
Byte::new_unchecked(self.0.slice(4..5))
}

pub fn nth5(&self) -> Byte {
Byte::new_unchecked(self.0.slice(5..6))
}

pub fn raw_data(&self) -> molecule::bytes::Bytes {
self.as_bytes()
}

pub fn as_reader<'r>(&'r self) -> Byte6Reader<'r> {
Byte6Reader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for Byte6 {
type Builder = Byte6Builder;

const NAME: &'static str = "Byte6";

fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
Byte6(data)
}

fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}

fn as_slice(&self) -> &[u8] {
&self.0[..]
}

fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
Byte6Reader::from_slice(slice).map(|reader| reader.to_entity())
}

fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
Byte6Reader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}

fn new_builder() -> Self::Builder {
::core::default::Default::default()
}

fn as_builder(self) -> Self::Builder {
Self::new_builder().set([
self.nth0(),
self.nth1(),
self.nth2(),
self.nth3(),
self.nth4(),
self.nth5(),
])
}
}
#[derive(Clone, Copy)]
pub struct Byte6Reader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for Byte6Reader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for Byte6Reader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for Byte6Reader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
let raw_data = hex_string(&self.raw_data());
write!(f, "{}(0x{})", Self::NAME, raw_data)
}
}
impl<'r> Byte6Reader<'r> {
pub const ITEM_COUNT: usize = 6;
pub const ITEM_SIZE: usize = 1;
pub const TOTAL_SIZE: usize = 6;

pub fn nth0(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[0..1])
}

pub fn nth1(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[1..2])
}

pub fn nth2(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[2..3])
}

pub fn nth3(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[3..4])
}

pub fn nth4(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[4..5])
}

pub fn nth5(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[5..6])
}

pub fn raw_data(&self) -> &'r [u8] {
self.as_slice()
}
}
impl<'r> molecule::prelude::Reader<'r> for Byte6Reader<'r> {
type Entity = Byte6;

const NAME: &'static str = "Byte6Reader";

fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}

fn new_unchecked(slice: &'r [u8]) -> Self {
Byte6Reader(slice)
}

fn as_slice(&self) -> &'r [u8] {
self.0
}

fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len != Self::TOTAL_SIZE {
return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
}
Ok(())
}
}
pub struct Byte6Builder(pub(crate) [Byte; 6]);
impl ::core::fmt::Debug for Byte6Builder {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:?})", Self::NAME, &self.0[..])
}
}
impl ::core::default::Default for Byte6Builder {
fn default() -> Self {
Byte6Builder([
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
])
}
}
impl Byte6Builder {
pub const ITEM_COUNT: usize = 6;
pub const ITEM_SIZE: usize = 1;
pub const TOTAL_SIZE: usize = 6;

pub fn set(mut self, v: [Byte; 6]) -> Self {
self.0 = v;
self
}

pub fn nth0(mut self, v: Byte) -> Self {
self.0[0] = v;
self
}

pub fn nth1(mut self, v: Byte) -> Self {
self.0[1] = v;
self
}

pub fn nth2(mut self, v: Byte) -> Self {
self.0[2] = v;
self
}

pub fn nth3(mut self, v: Byte) -> Self {
self.0[3] = v;
self
}

pub fn nth4(mut self, v: Byte) -> Self {
self.0[4] = v;
self
}

pub fn nth5(mut self, v: Byte) -> Self {
self.0[5] = v;
self
}
}
impl molecule::prelude::Builder for Byte6Builder {
type Entity = Byte6;

const NAME: &'static str = "Byte6Builder";

fn expected_length(&self) -> usize {
Self::TOTAL_SIZE
}

fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
writer.write_all(self.0[0].as_slice())?;
writer.write_all(self.0[1].as_slice())?;
writer.write_all(self.0[2].as_slice())?;
writer.write_all(self.0[3].as_slice())?;
writer.write_all(self.0[4].as_slice())?;
writer.write_all(self.0[5].as_slice())?;
Ok(())
}

fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
Byte6::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct Byte32(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for Byte32 {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
Expand Down
17 changes: 17 additions & 0 deletions src/extension.mol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import common;

vector LockScriptVec <Bytes>;
vector ExtensionVec <Byte32>;

table ExtensionLeaves {
keys: ExtensionVec,
values: ExtensionVec,
old_values: ExtensionVec,
proof: Bytes,
}

table ExtensionEntries {
leaves: ExtensionLeaves,
sub_type: Byte6,
raw_data: Bytes,
}
Loading

0 comments on commit d67ea75

Please sign in to comment.