generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfc7770
commit 7ce941b
Showing
5 changed files
with
51 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "message" | ||
version = "0.1.0" | ||
description = "Message struct to use within Hashi" | ||
edition = "2021" | ||
|
||
[features] | ||
default = [] | ||
cpi = ["no-entrypoint"] | ||
no-entrypoint = [] | ||
no-idl = [] | ||
no-log-ix-name = [] | ||
idl-build = ["anchor-lang/idl-build"] | ||
|
||
[dependencies] | ||
anchor-lang = "0.30.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use anchor_lang::prelude::*; | ||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
use std::convert::From; | ||
|
||
#[derive(BorshDeserialize, BorshSerialize)] | ||
pub struct Message { | ||
pub ids: Vec<[u8; 32]>, | ||
pub hashes: Vec<[u8; 32]>, | ||
} | ||
|
||
impl From<(u64, [u8; 32])> for Message { | ||
fn from(value: (u64, [u8; 32])) -> Self { | ||
let (id, hash) = value; | ||
Message { | ||
ids: vec![u64_to_u8_32(id)], | ||
hashes: vec![hash], | ||
} | ||
} | ||
} | ||
|
||
fn u64_to_u8_32(number: u64) -> [u8; 32] { | ||
let mut bytes = [0u8; 32]; | ||
let number_bytes = number.to_be_bytes(); | ||
bytes[24..].copy_from_slice(&number_bytes); | ||
bytes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters