Skip to content

Commit

Permalink
Added result path to the contract
Browse files Browse the repository at this point in the history
  • Loading branch information
igorperic17 committed Nov 9, 2023
1 parent 5b45886 commit ba09973
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 7 additions & 6 deletions contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl TaskContract {
format!("Task created successfully: {}", task)
}

pub fn submit_result(&mut self, task_id: String, result_hash: String) -> String {
pub fn submit_result(&mut self, task_id: String, result_url: String, result_hash: String) -> String {
// If the item is no longer in the task_items map it has already been fulfilled:
if !self.task_items.contains_key(&task_id) {
return "This task has already been fulfilled!".to_string();
Expand All @@ -54,7 +54,7 @@ impl TaskContract {
|| env::signer_account_id()
== AccountId::new_unchecked("obrigado.testnet".to_string())
{
self.add_confirmation(&mut task, result_hash);
self.add_confirmation(&mut task, result_hash, result_url);

// If the task has noew reached the minimum number of required confirmations move the task to history and send NEAR to confirming accounts:
if task.confirmation_count >= MINIMUM_CONFIRMATION_COUNT {
Expand Down Expand Up @@ -141,9 +141,9 @@ impl TaskContract {
self.task_items.remove(&task.id);
}

fn add_confirmation(&mut self, task: &mut Task, result_hash: String) {
fn add_confirmation(&mut self, task: &mut Task, result_hash: String, result_url: String) {
task.confirmations
.insert(env::signer_account_id(), Confirmation::new(result_hash));
.insert(env::signer_account_id(), Confirmation::new(result_hash, result_url));

task.confirmation_count = U128(task.confirmation_count.0 + 1);

Expand Down Expand Up @@ -221,11 +221,12 @@ impl fmt::Display for Task {
#[derive(BorshDeserialize, BorshSerialize)]
pub struct Confirmation {
result_hash: String,
result_url: String
}

impl Confirmation {
fn new(result_hash: String) -> Self {
Self { result_hash }
fn new(result_hash: String, result_url: String) -> Self {
Self { result_hash, result_url }
}
}

Expand Down
4 changes: 1 addition & 3 deletions worker-node/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ async function uploadResultsToIPFS(workspaceDir) {

// Function to submit the result to the smart contract
async function submitResultToContract(contract, taskId, resultUrl, resultHash) {
// Submit the result to the smart contract
// This is a placeholder function. You'll need to implement the actual contract call.
await contract.submit_result({ task_id: taskId, resultHash: resultHash });
}

// Function to process a task
Expand Down Expand Up @@ -162,7 +161,6 @@ async function listenToJobQueue() {
});



// {
// submitter_account_id: 'develoco.testnet',
// bounty: 21,
Expand Down

0 comments on commit ba09973

Please sign in to comment.