Skip to content

Commit

Permalink
Added minor state changes to the gummyroll contract (solana-labs#106)
Browse files Browse the repository at this point in the history
* Added minor state changes to the gummyroll contract

* client fixes
  • Loading branch information
jarry-xiao authored Jun 16, 2022
1 parent 5baa9ed commit 04b15d0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contracts/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 7 additions & 1 deletion contracts/programs/gummyroll/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)?;

Expand Down
9 changes: 6 additions & 3 deletions contracts/programs/gummyroll/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ pub struct ChangeLogEvent {
pub id: Pubkey,
/// Nodes of off-chain merkle tree
pub path: Vec<PathNode>,
pub seq: u128,
pub seq: u64,
/// Bitmap of node parity (used when hashing)
pub index: u32,
}
// ChangeLog<MAX_DEPTH>
impl<const MAX_DEPTH: usize> From<(Box<ChangeLog<MAX_DEPTH>>, Pubkey, u128)>
impl<const MAX_DEPTH: usize> From<(Box<ChangeLog<MAX_DEPTH>>, Pubkey, u64)>
for Box<ChangeLogEvent>
{
fn from(log_info: (Box<ChangeLog<MAX_DEPTH>>, Pubkey, u128)) -> Self {
fn from(log_info: (Box<ChangeLog<MAX_DEPTH>>, Pubkey, u64)) -> Self {
let (changelog, tree_id, seq) = log_info;
let path_len = changelog.path.len() as u32;
let mut path: Vec<PathNode> = changelog
Expand Down Expand Up @@ -69,6 +69,7 @@ pub struct MerkleRollHeader {
pub max_depth: u32,
pub authority: Pubkey,
pub append_authority: Pubkey,
pub creation_slot: u64,
}

impl MerkleRollHeader {
Expand All @@ -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);
Expand All @@ -86,5 +88,6 @@ impl MerkleRollHeader {
self.max_depth = max_depth;
self.authority = *authority;
self.append_authority = *append_authority;
self.creation_slot = creation_slot;
}
}
4 changes: 3 additions & 1 deletion contracts/sdk/gummyroll/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type MerkleRollHeader = {
maxBufferSize: number; // u32
authority: PublicKey;
appendAuthority: PublicKey;
creationSlot: BN;
};

type MerkleRoll = {
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 04b15d0

Please sign in to comment.