Skip to content

Commit

Permalink
feat(add_member_with_threshold): added discriminator
Browse files Browse the repository at this point in the history
  • Loading branch information
ogmedia committed Aug 18, 2022
1 parent 2277419 commit 716f249
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 6 additions & 2 deletions programs/squads-mpl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,17 @@ pub mod squads_mpl {
ix_account_infos.push(ix_program_info.clone());

let add_member_discriminator = Vec::from_hex("0d747b827ec63922").unwrap();

let add_member_and_change_threshold_discriminator = Vec::from_hex("72d53b2fd69d96aa").unwrap();
// loop through the provided remaining accounts
for account_index in 0..ix_keys.len() {
let ix_account_info = next_account_info(ix_iter)?.clone();

// check if this data has length of 8 or greater, and is our discriminator
if ctx.program_id == ix_program_info.key && Some(add_member_discriminator.as_slice()) == ix.data.get(0..8) && account_index == 2 {
if ctx.program_id == ix_program_info.key &&
(
Some(add_member_discriminator.as_slice()) == ix.data.get(0..8) ||
Some(add_member_and_change_threshold_discriminator.as_slice()) == ix.data.get(0..8)
) && account_index == 2 {
// check that the ix account keys match the submitted account keys
if *ix_account_info.key != *ctx.accounts.member.key {
return err!(MsError::InvalidInstructionAccount);
Expand Down
11 changes: 7 additions & 4 deletions sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,16 @@ class Squads {
.map(({ pubkey, ixItem }) => {
const ixKeys: anchor.web3.AccountMeta[] =
ixItem.keys as anchor.web3.AccountMeta[];
const sig = anchor.utils.sha256.hash("global:add_member");
const ixDiscriminator = Buffer.from(sig, "hex");
const data = Buffer.concat([ixDiscriminator.slice(0, 8)]);
const addSig = anchor.utils.sha256.hash("global:add_member");
const ixDiscriminator = Buffer.from(addSig, "hex");
const addData = Buffer.concat([ixDiscriminator.slice(0, 8)]);
const addAndThreshSig = anchor.utils.sha256.hash("global:add_member_and_change_threshold");
const ixAndThreshDiscriminator = Buffer.from(addAndThreshSig, "hex");
const addAndThreshData = Buffer.concat([ixAndThreshDiscriminator.slice(0, 8)]);
const ixData = ixItem.data as any;

const formattedKeys = ixKeys.map((ixKey, keyInd) => {
if (ixData.includes(data) && keyInd === 2) {
if ((ixData.includes(addData) || ixData.includes(addAndThreshData)) && keyInd === 2) {
return {
pubkey: payer.publicKey,
isSigner: false,
Expand Down

0 comments on commit 716f249

Please sign in to comment.