lib.rs 805 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. use borsh::{BorshDeserialize, BorshSerialize};
  2. use drk_sdk::{
  3. entrypoint,
  4. error::{ContractError, ContractResult},
  5. msg,
  6. };
  7. use pasta_curves::pallas;
  8. use darkfi::serial::{deserialize, SerialDecodable, SerialEncodable};
  9. #[derive(BorshSerialize, BorshDeserialize)]
  10. pub struct Args {
  11. pub a: pallas::Base,
  12. pub b: pallas::Base,
  13. }
  14. #[derive(SerialEncodable, SerialDecodable)]
  15. pub struct Foo {
  16. pub a: u64,
  17. pub b: u64,
  18. }
  19. entrypoint!(process_instruction);
  20. fn process_instruction(ix: &[u8]) -> ContractResult {
  21. //let args = Args::try_from_slice(ix)?;
  22. let args: Foo = deserialize(ix)?;
  23. if args.a < args.b {
  24. return Err(ContractError::Custom(69))
  25. }
  26. let sum = args.a + args.b;
  27. msg!("Hello from the VM runtime!");
  28. msg!("Sum: {:?}", sum);
  29. Ok(())
  30. }