Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Data #469

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/hello_world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export async function sayHello(): Promise<void> {
const instruction = new TransactionInstruction({
keys: [{pubkey: greetedPubkey, isSigner: false, isWritable: true}],
programId,
data: Buffer.alloc(0), // All instructions are hellos
data: Buffer.from('hello', 'utf8'), // say 'hello'
});
await sendAndConfirmTransaction(
connection,
Expand Down
11 changes: 10 additions & 1 deletion src/program-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@ entrypoint!(process_instruction);
pub fn process_instruction(
program_id: &Pubkey, // Public key of the account the hello world program was loaded into
accounts: &[AccountInfo], // The account to say hello to
_instruction_data: &[u8], // Ignored, all helloworld instructions are hellos
instruction_data: &[u8], // The message from the greeter
) -> ProgramResult {
msg!("Hello World Rust program entrypoint");

// Iterating accounts is safer than indexing
let accounts_iter = &mut accounts.iter();

let message_from_sender = String::from_utf8_lossy(instruction_data);

if message_from_sender != "hello" {
msg!("You Forgot To Say 'hello'");
msg!("You said '{:?}'",String::from_utf8_lossy(instruction_data));

return Err(ProgramError::InvalidInstructionData);
}

// Get the account to say hello to
let account = next_account_info(accounts_iter)?;

Expand Down