Giter VIP home page Giter VIP logo

solana_reflect's Introduction

Solana_Reflect

Rust Code

this code let developers generate function id and match function name with function automatically in the compile-time. Anyone who witre solana contract may spare themselve from counting the function number and allocating id to functions;

Dingirsu_Reflect!{

    impl D_Processer {
        pub fn A(
            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
        ) -> ProgramResult {
            msg!("A");
            print!("A");
            Ok(())
        }
        pub fn B(
            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
        ) -> ProgramResult {
            msg!("B");
            print!("B");
            Ok(())
        }
    }

}
#[cfg(test)]
..
let mut instruction_data: Vec<u8> = Vec::new();
let mut s=String::from("A\0");
let datas=s.as_bytes();
for  i in datas
{
    instruction_data.push(*i);
}
..
process_instruction(&program_id, &accounts, &instruction_data).unwrap();

JS

The instruction data starts with a string wihch is a function name and ends with '\0'

    let t_data=Buffer.alloc(4);
    t_data[0]=65;
    t_data[1]=0;

    console.log('Saying hello to', prog.toBase58());
    const instruction = new TransactionInstruction({
      keys: [{pubkey: greetedPubkey, isSigner: false, isWritable: true}],
      programId:prog,
      data:t_data, // All instructions are hellos
    });
    let res= await sendAndConfirmTransaction(
      connection,
      new Transaction().add(instruction),
      [acc],
      {
        commitment: 'singleGossip',
        preflightCommitment: 'singleGossip',
      },
    );

Program Log

    Program 54wzi12wkAq9vEtvxqVZBcgESm9aArrtzcReN7kJ8mwQ invoke [1]
    Hello!
    Reflect to function A
    Program 54wzi12wkAq9vEtvxqVZBcgESm9aArrtzcReN7kJ8mwQ consumed 966 of 200000 compute units
    Program 54wzi12wkAq9vEtvxqVZBcgESm9aArrtzcReN7kJ8mwQ success

prospect

  • Fix bugs during reflect p-macros
  • Multi-Programing-Language suppport for Solana api
  • Some other aspire that I've not got yet

solana_reflect's People

Contributors

archenetwork avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.