Skip to content

Commit

Permalink
charlie-contract: removed subsidy types crate
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed May 21, 2024
1 parent 881e0b2 commit e8df502
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion contracts/charlie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ resolver = "2"
crate-type = ["cdylib", "rlib"]

[dependencies]
rkyv = { version = "0.7", default-features = false, features = ["size_32"] }
bytecheck = { version = "0.6", default-features = false }
bls12_381-bls = { version = "0.2", default-features = false, features = ["rkyv-impl"] }
phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl", "alloc"] }
rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", features = ["dlmalloc"] }
dusk-bytes = "0.1"
transfer-contract-types = { version = "0.1.0", path = "../transfer-types", default-features = false }
subsidy-types = { version = "0.0.1", path = "../subsidy-types", default-features = false }
35 changes: 34 additions & 1 deletion contracts/charlie/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,46 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use alloc::vec::Vec;
use bls12_381_bls::{PublicKey, Signature};
use dusk_bytes::Serializable;
use rkyv::{Archive, Deserialize, Serialize};
use rusk_abi::TRANSFER_CONTRACT;
use subsidy_types::*;
use transfer_contract_types::Stct;

#[derive(Debug, Clone)]
pub struct Charlie;

/// Subsidy a contract with a value.
#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
#[archive_attr(derive(bytecheck::CheckBytes))]
pub struct Subsidy {
/// Public key to which the subsidy will belong.
pub public_key: PublicKey,
/// Signature belonging to the given public key.
pub signature: Signature,
/// Value of the subsidy.
pub value: u64,
/// Proof of the `STCT` circuit.
pub proof: Vec<u8>,
}

const SUBSIDY_MESSAGE_SIZE: usize = u64::SIZE + u64::SIZE;

/// Return the digest to be signed in the `subsidize` function of a contract.
#[must_use]
pub fn subsidy_signature_message(
counter: u64,
value: u64,
) -> [u8; SUBSIDY_MESSAGE_SIZE] {
let mut bytes = [0u8; SUBSIDY_MESSAGE_SIZE];

bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes());
bytes[u64::SIZE..].copy_from_slice(&value.to_bytes());

bytes
}

impl Charlie {
fn gas_price() -> u64 {
rusk_abi::call::<(), u64>(TRANSFER_CONTRACT, "gas_price", &())
Expand Down

0 comments on commit e8df502

Please sign in to comment.