From 04b15d047b18f65e56018934d6ca16348d0f117a Mon Sep 17 00:00:00 2001 From: Jarry Xiao <61092285+jarry-xiao@users.noreply.github.com> Date: Thu, 16 Jun 2022 11:28:40 -0500 Subject: [PATCH] Added minor state changes to the gummyroll contract (#106) * Added minor state changes to the gummyroll contract * client fixes --- contracts/Anchor.toml | 2 +- contracts/programs/gummyroll/src/lib.rs | 8 +++++++- contracts/programs/gummyroll/src/state/mod.rs | 9 ++++++--- contracts/sdk/gummyroll/accounts/index.ts | 4 +++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/contracts/Anchor.toml b/contracts/Anchor.toml index b90f7ff782f..1b4e55a0a24 100644 --- a/contracts/Anchor.toml +++ b/contracts/Anchor.toml @@ -28,4 +28,4 @@ cluster = "localnet" wallet = "~/.config/solana/id.json" [scripts] -test = "yarn run ts-mocha -t 1000000 tests/**/bubblegum-test.ts" +test = "yarn run ts-mocha -t 1000000 tests/**/*-test.ts" diff --git a/contracts/programs/gummyroll/src/lib.rs b/contracts/programs/gummyroll/src/lib.rs index d3c6acfd4f7..cce1e118965 100644 --- a/contracts/programs/gummyroll/src/lib.rs +++ b/contracts/programs/gummyroll/src/lib.rs @@ -1,4 +1,8 @@ -use anchor_lang::{emit, prelude::*, solana_program::sysvar::rent::Rent}; +use anchor_lang::{ + emit, + prelude::*, + solana_program::sysvar::{clock::Clock, rent::Rent}, +}; use borsh::{BorshDeserialize, BorshSerialize}; use std::mem::size_of; @@ -156,6 +160,7 @@ pub mod gummyroll { max_buffer_size, &ctx.accounts.authority.key(), &ctx.accounts.append_authority.key(), + Clock::get()?.slot, ); header.serialize(&mut header_bytes)?; let id = ctx.accounts.merkle_roll.key(); @@ -189,6 +194,7 @@ pub mod gummyroll { max_buffer_size, &ctx.accounts.authority.key(), &ctx.accounts.append_authority.key(), + Clock::get()?.slot, ); header.serialize(&mut header_bytes)?; diff --git a/contracts/programs/gummyroll/src/state/mod.rs b/contracts/programs/gummyroll/src/state/mod.rs index 9b68d6dad0f..e92ee8d1f41 100644 --- a/contracts/programs/gummyroll/src/state/mod.rs +++ b/contracts/programs/gummyroll/src/state/mod.rs @@ -30,15 +30,15 @@ pub struct ChangeLogEvent { pub id: Pubkey, /// Nodes of off-chain merkle tree pub path: Vec, - pub seq: u128, + pub seq: u64, /// Bitmap of node parity (used when hashing) pub index: u32, } // ChangeLog -impl From<(Box>, Pubkey, u128)> +impl From<(Box>, Pubkey, u64)> for Box { - fn from(log_info: (Box>, Pubkey, u128)) -> Self { + fn from(log_info: (Box>, Pubkey, u64)) -> Self { let (changelog, tree_id, seq) = log_info; let path_len = changelog.path.len() as u32; let mut path: Vec = changelog @@ -69,6 +69,7 @@ pub struct MerkleRollHeader { pub max_depth: u32, pub authority: Pubkey, pub append_authority: Pubkey, + pub creation_slot: u64, } impl MerkleRollHeader { @@ -78,6 +79,7 @@ impl MerkleRollHeader { max_buffer_size: u32, authority: &Pubkey, append_authority: &Pubkey, + creation_slot: u64, ) { // Check header is empty assert_eq!(self.max_buffer_size, 0); @@ -86,5 +88,6 @@ impl MerkleRollHeader { self.max_depth = max_depth; self.authority = *authority; self.append_authority = *append_authority; + self.creation_slot = creation_slot; } } diff --git a/contracts/sdk/gummyroll/accounts/index.ts b/contracts/sdk/gummyroll/accounts/index.ts index 2405caafef1..90a54a9865e 100644 --- a/contracts/sdk/gummyroll/accounts/index.ts +++ b/contracts/sdk/gummyroll/accounts/index.ts @@ -46,6 +46,7 @@ type MerkleRollHeader = { maxBufferSize: number; // u32 authority: PublicKey; appendAuthority: PublicKey; + creationSlot: BN; }; type MerkleRoll = { @@ -83,10 +84,11 @@ export function decodeMerkleRoll(buffer: Buffer): OnChainMerkleRoll { maxDepth: reader.readU32(), authority: readPublicKey(reader), appendAuthority: readPublicKey(reader), + creationSlot: reader.readU64(), }; // Decode MerkleRoll - let sequenceNumber = reader.readU128(); + let sequenceNumber = reader.readU64(); let activeIndex = reader.readU64().toNumber(); let bufferSize = reader.readU64().toNumber();