-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtester.sol
More file actions
56 lines (49 loc) · 2.18 KB
/
tester.sol
File metadata and controls
56 lines (49 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract TransactionRegistry {
// Struct to represent a compute transaction
struct ComputeTransaction {
uint256 requestDate;
string status;
uint256 computeTime;
uint256 fee;
string computeID;
string logCID;
bytes32 currentTransactionHash;
address caller; // New field to store the caller's address
}
// Mapping to store transactions using their transaction hash as a key
mapping(string => mapping(address => ComputeTransaction)) public computeTransactions;
// Function to add a new compute transaction
function addTransaction(
string memory _computeID,
string memory _status,
uint256 _computeTime,
uint256 _fee,
string memory _logCID
) external {
// Check if the transaction already exists for the caller
require(bytes(computeTransactions[_computeID][msg.sender].computeID).length == 0, "Transaction already exists");
// Create a new transaction
ComputeTransaction memory newTransaction = ComputeTransaction({
requestDate: block.timestamp,
status: _status,
computeTime: _computeTime,
fee: _fee,
computeID: _computeID,
logCID: _logCID,
currentTransactionHash: keccak256(abi.encodePacked(block.timestamp, msg.sender, blockhash(block.number - 1))),
caller: msg.sender
});
// Add the new transaction to the mapping using the transaction hash and caller's address
computeTransactions[_computeID][msg.sender] = newTransaction;
}
// Function to update the status and fee of a compute transaction
function updateTransaction(string memory _computeID, string memory _status, uint256 _fee) external {
// Check if the transaction exists for the caller
require(bytes(computeTransactions[_computeID][msg.sender].computeID).length != 0, "Transaction does not exist");
// Update the status and fee of the transaction
computeTransactions[_computeID][msg.sender].status = _status;
computeTransactions[_computeID][msg.sender].fee = _fee;
}
}