Skip to content

Commit

Permalink
send message content with event
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit committed Oct 17, 2023
1 parent 5fd89b7 commit 8963aca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
5 changes: 5 additions & 0 deletions api/src/events/processor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fireblocks::Fireblocks;
use hub_core::{
bs58,
prelude::*,
producer::{Producer, SendError},
thiserror, uuid,
Expand Down Expand Up @@ -49,6 +50,8 @@ pub enum ProcessorError {
MissingSafeTransferFromTxn,
#[error("Signed message not found in transaction response")]
MissingSignedMessage,
#[error("Invalid number of signer pubkeys")]
InvalidNumberOfSigners,

#[error("Invalid ECDSA pubkey recovery scalar")]
#[permanent]
Expand All @@ -68,6 +71,8 @@ pub enum ProcessorError {
DbError(#[from] DbErr),
#[error("Error sending message")]
SendError(#[from] SendError),
#[error("Base58 decode error")]
Bs58DecodeError(#[from] bs58::decode::Error),
}

pub type Result<T> = std::result::Result<T, ProcessorError>;
Expand Down
29 changes: 16 additions & 13 deletions api/src/events/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ impl<'a> Solana<'a> {
let fireblocks = &self.0.fireblocks;
let pubkeys = payload.signers_pubkeys.clone();

if pubkeys.len() != 2 {
return Err(ProcessorError::InvalidNumberOfSigners);
}

let note = &format!(
"Mint batch signing for collection {:?} by {:?} for project {:?}",
key.id, key.user_id, key.project_id,
Expand Down Expand Up @@ -220,35 +224,34 @@ impl<'a> Solana<'a> {
let signatures = futs_result[0]
.clone()
.into_iter()
.zip(futs_result[1].clone().into_iter())
.zip(
payload
.mint_transactions
.iter()
.map(|m| m.signer_signature.clone()),
)
.zip(futs_result[1].clone().into_iter())
.map(|((a, b), c)| (a, b, c))
.collect::<Vec<_>>();

for (sig1, sig2, sig3) in signatures {
for ((sig1, sig2), sig3) in signatures {
let key = key.clone();
let mut signatures = Vec::new();
let content = bs58::decode(sig1.content).into_vec()?;

let sig1_bytes = <[u8; 64]>::from_hex(sig1.signature.full_sig)?;
let sig1 = bs58::encode(sig1_bytes).into_string();

let sig3_bytes = <[u8; 64]>::from_hex(sig3.signature.full_sig)?;
let sig3 = bs58::encode(sig3_bytes).into_string();
signatures.push(bs58::encode(sig1_bytes).into_string());

let mut signed_message_signatures = vec![sig1, sig3];
let sig2_bytes = <[u8; 64]>::from_hex(sig2.signature.full_sig)?;
signatures.push(bs58::encode(sig2_bytes).into_string());

// this will be true if mint is uncompressed
if let Some(sig2) = sig2 {
signed_message_signatures.insert(1, sig2);
// Uncompressed mint message needs to be signed by mint key pair
if let Some(sig3) = sig3 {
signatures.insert(1, sig3);
}

let txn = SolanaTransactionResult {
serialized_message: None,
signed_message_signatures,
serialized_message: Some(content),
signed_message_signatures: signatures,
status: TransactionStatus::Completed.into(),
};

Expand Down

0 comments on commit 8963aca

Please sign in to comment.