Skip to content

Commit

Permalink
Fix reclaim gpt contract build
Browse files Browse the repository at this point in the history
  • Loading branch information
Sliman4 committed Dec 13, 2024
1 parent 526688a commit c6ad2b7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
4 changes: 4 additions & 0 deletions crates/oracle-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ near-sdk-contract-tools = "3.0.2"
near-workspaces = { version = "0.15.0", features = ["unstable"] }
tokio = { version = "1.12.0", features = ["full"] }
serde_json = "1"

[features]
default = ["contract"]
contract = []
24 changes: 9 additions & 15 deletions crates/oracle-contract/src/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ use near_sdk::{
env, json_types::U128, log, near, serde_json, AccountId, Gas, NearToken, Promise,
PromiseOrValue,
};
use near_sdk_contract_tools::ft::Nep141Receiver;

use crate::{producer::ProducerId, Oracle, OracleExt};
use crate::producer::ProducerId;
#[cfg(feature = "contract")]
use crate::{Oracle, OracleExt};

pub type FtId = AccountId;

#[cfg(feature = "contract")]
#[near]
impl Oracle {
#[payable]
Expand Down Expand Up @@ -177,20 +181,10 @@ struct FtDepositArgs {
pub producer_id: Option<ProducerId>,
}

// TODO: Can't use git near-sdk with near-sdk-contract-tools
//
// impl Nep141Receiver for Contract {
// fn ft_on_transfer(
// &mut self,
// sender_id: AccountId,
// amount: U128,
// msg: String,
// ) -> PromiseOrValue<U128> {
//
// }
// }
impl Oracle {
pub fn ft_on_transfer(
#[cfg(feature = "contract")]
#[near]
impl Nep141Receiver for Oracle {
fn ft_on_transfer(
&mut self,
sender_id: AccountId,
amount: U128,
Expand Down
5 changes: 4 additions & 1 deletion crates/oracle-contract/src/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ use near_sdk::{
use crate::{
balance::FtId,
producer::{ext_producer, ProducerId},
Oracle, OracleExt, StorageKey,
StorageKey,
};
#[cfg(feature = "contract")]
use crate::{Oracle, OracleExt};

const RESUMPTION_TOKEN_REGISTER: u64 = 69;

Expand Down Expand Up @@ -64,6 +66,7 @@ pub struct RequestEventV1 {
pub request_data: String,
}

#[cfg(feature = "contract")]
#[near]
impl Oracle {
pub fn register_consumer(&mut self, account_id: ConsumerId) {
Expand Down
6 changes: 5 additions & 1 deletion crates/oracle-contract/src/fees.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use near_sdk::{env, json_types::U128, near, NearToken, Promise};

use crate::{balance::FtId, consumer::ConsumerId, producer::ProducerId, Oracle, OracleExt};
use crate::{balance::FtId, consumer::ConsumerId, producer::ProducerId};
#[cfg(feature = "contract")]
use crate::{Oracle, OracleExt};

/// Fees are set by producers. If the consumer's balance is less
/// than prepaid_amount, the request will be rejected without a log generated.
Expand Down Expand Up @@ -39,6 +41,7 @@ pub enum PaymentType {
AttachedToCall,
}

#[cfg(feature = "contract")]
#[near]
impl Oracle {
pub fn get_fee(&self, producer_id: &ProducerId) -> Option<ProducerFee> {
Expand All @@ -55,6 +58,7 @@ impl Oracle {
}
}

#[cfg(feature = "contract")]
impl Oracle {
pub fn try_charge_fee(
&mut self,
Expand Down
4 changes: 4 additions & 0 deletions crates/oracle-contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(feature = "contract"), allow(unused_imports, dead_code))]

pub mod balance;
pub mod consumer;
pub mod fees;
Expand Down Expand Up @@ -31,13 +33,15 @@ enum StorageKey {
}

// TODO: Storage management
#[cfg(feature = "contract")]
#[near(contract_state)]
pub struct Oracle {
producers: LookupMap<ProducerId, Producer>,
consumers: LookupMap<ConsumerId, Consumer>,
next_request_id: RequestId,
}

#[cfg(feature = "contract")]
impl Default for Oracle {
fn default() -> Self {
Self {
Expand Down
6 changes: 5 additions & 1 deletion crates/oracle-contract/src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use near_sdk::{
use crate::{
consumer::{ConsumerId, PendingRequest, RequestId},
fees::{PrepaidFee, ProducerFee},
Oracle, OracleExt, StorageKey,
StorageKey,
};
#[cfg(feature = "contract")]
use crate::{Oracle, OracleExt};

pub type ProducerId = AccountId;

Expand Down Expand Up @@ -41,6 +43,7 @@ pub trait ProducerContract {
fn on_request(&mut self, request_id: RequestId, request_data: String, prepaid_fee: PrepaidFee);
}

#[cfg(feature = "contract")]
#[near]
impl Oracle {
pub fn add_producer(&mut self, account_id: ProducerId) {
Expand Down Expand Up @@ -107,6 +110,7 @@ pub trait OracleResponder {
fn respond(&mut self, request_id: RequestId, response: Response);
}

#[cfg(feature = "contract")]
#[near]
impl OracleResponder for Oracle {
fn respond(&mut self, request_id: RequestId, response: Response) {
Expand Down
2 changes: 1 addition & 1 deletion crates/reclaim-gpt-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ crate-type = ["cdylib", "rlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
near-sdk = "5.5"
intear-oracle = { path = "../oracle-contract" }
intear-oracle = { path = "../oracle-contract", default-features = false }

[dev-dependencies]
near-sdk = { version = "5.1.0", features = ["unit-testing"] }
Expand Down

0 comments on commit c6ad2b7

Please sign in to comment.