Skip to content

Commit

Permalink
Groundwork for requests to rent something
Browse files Browse the repository at this point in the history
  • Loading branch information
yanliu38 committed Dec 3, 2024
1 parent f852249 commit bf0e707
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
2 changes: 2 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod ledger_refresh;
pub mod offerings;
pub mod profiles;
pub mod registration;
pub mod renting;
pub mod rewards;

pub use account_transfers::*;
Expand All @@ -25,6 +26,7 @@ use num_traits::cast::ToPrimitive;
pub use offerings::*;
pub use profiles::*;
pub use registration::*;
pub use renting::*;
pub use rewards::*;

#[cfg(not(target_arch = "wasm32"))]
Expand Down
56 changes: 56 additions & 0 deletions common/src/renting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::{
amount_as_string, charge_fees_to_account_no_bump_reputation, info, reward_e9s_per_block, warn,
Balance, DccIdentity, ED25519_SIGNATURE_LENGTH, LABEL_NP_OFFERING, MAX_NP_OFFERING_BYTES,
MAX_PUBKEY_BYTES,
};

pub struct OfferingRequestPayloadV1 {
requester_pubkey_bytes: Vec<u8>,
requester_ssh_pubkey: String,
requester_contact: String,
provider_pubkey_bytes: Vec<u8>,
offering_id: String,
instance_id: Option<String>,
instance_config: Option<String>,
payment_amount: u64,
rent_period_seconds: u64,
rent_start_timestamp: Option<u64>,
request_memo: String,
signature: Vec<u8>,
}

pub enum OfferingRequestPayload {
V1(OfferingRequestPayloadV1),
}

impl OfferingRequestPayload {
fn new(
requester_pubkey_bytes: Vec<u8>,
requester_ssh_pubkey: String,
requester_contact: String,
provider_pubkey_bytes: Vec<u8>,
offering_id: String,
instance_id: Option<String>,
instance_config: Option<String>,
payment_amount: u64,
rent_period_seconds: u64,
rent_start_timestamp: Option<u64>,
request_memo: String,
signature: Vec<u8>,
) -> Self {
OfferingRequestPayload::V1(OfferingRequestPayloadV1 {
requester_pubkey_bytes,
requester_ssh_pubkey,
requester_contact,
provider_pubkey_bytes,
offering_id,
instance_id,
instance_config,
payment_amount,
rent_period_seconds,
rent_start_timestamp,
request_memo,
signature,
})
}
}
34 changes: 33 additions & 1 deletion ic-canister/decent_cloud.did
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,37 @@ type ResultData = variant { Ok: record { text; vec nat8 }; Err: text; };
type OfferingEntry = record {
np_pub_key: vec nat8;
offering_compressed: vec nat8;
}
};

type OfferingRentRequest = record {
requester_pubkey_bytes: vec nat8; // Who is making this rent request?
requester_ssh_pubkey: text; // The ssh key that will be given access to the instance, preferably in ed25519 key format https://en.wikipedia.org/wiki/Ssh-keygen
requester_contact: text; // Where can the requester be contacted by the provided, if needed
provider_pubkey_bytes: vec nat8; // To which provider is this targeted?
offering_id: text; // Requester would like to rent this particular offering id
instance_id: opt text; // optional instance id that can be provided to alter the particular instance a requester already controls
instance_config: opt text; // optional configuration for the rented instance, e.g. cloud-init
payment_amount: nat; // How much is the requester offering to pay for renting the resource
rent_period_seconds: nat; // For how many SECONDS would the requester like to rent the resource; 1 hour = 3600 seconds, 1 day = 86400 seconds
rent_start_timestamp: opt nat; // Optionally, only start renting at this unix time (in seconds) UTC. This can be in the future.
request_memo: text; // Reference to this particular request; arbitrary text. Can be used e.g. for administrative purposes
signature: vec nat8; // The whole request needs to be signed by the requester's private key
};

type OfferingRentReply = record {
requester_pubkey_bytes: vec nat8; // Public key of the original requester
request_memo: text; // Memo field of the original request
rent_success: bool; // Short boolean to mark whether the renting was accepted or rejected by the provider
response_text: text; // Thank you note, or similar on success. Reason the request failed on failure.
response_details: text; // Instructions or a link to the detailed instructions: describing next steps, further information, etc.
signature: vec nat8; // Signature of the response, to simplify verification
};

type RefundRequest = record { // TODO
requester_pubkey_bytes: vec nat8; // Who is making this request?
instance_id: text; // instance id for which a refund is requested
signature: vec nat8; // The whole request needs to be signed by the requester's private key
};

service : {
// Node Provider (NP) management operations
Expand All @@ -365,6 +395,8 @@ service : {
node_provider_get_profile_by_principal: (principal) -> (opt text) query;
get_np_check_in_nonce: () -> (vec nat8) query;
offering_search: (search_query: text) -> (vec OfferingEntry) query;
offering_request: (OfferingRentRequest) -> (ResultString);
offering_reply: (OfferingRentReply) -> (ResultString);

// User management operations
user_register: (pubkey_bytes: vec nat8, reserved: vec nat8) -> (ResultString);
Expand Down
9 changes: 9 additions & 0 deletions ic-canister/tests/test_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,15 @@ fn offering_search<T: AsRef<str> + candid::CandidType + ?Sized>(
.collect()
}

// fn offering_request(
// pic: &PocketIc,
// can: Principal,
// dcc_id: &DccIdentity,
// offering_id: &str,
// ) -> Result<String, String> {

// }

#[test]
fn test_offerings() {
let (p, c) = create_test_canister();
Expand Down

0 comments on commit bf0e707

Please sign in to comment.