-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChainlinkOraclePrice.sol
More file actions
43 lines (34 loc) · 1.08 KB
/
Copy pathChainlinkOraclePrice.sol
File metadata and controls
43 lines (34 loc) · 1.08 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
// Define the data types used by the contract.
struct Asset {
string name;
uint price;
}
struct Source {
string name;
uint price;
}
// Define the contract.
contract ChainlinkPriceOracle {
// Define the assets tracked by the contract.
Asset[] public assets;
// Define the data sources used by the contract.
Source[] public sources;
// Define the mapping to store the current prices.
mapping (string => uint) public prices;
// Function to update the price of an asset.
function updatePrice(string memory _asset, uint _price) public {
// Update the price of the asset in the mapping.
prices[_asset] = _price;
// Log the updated price.
emit PriceUpdated(_asset, _price);
}
// Function to query the current price of an asset.
function getPrice(string memory _asset) public view returns (uint) {
// Return the current price of the asset from the mapping.
return prices[_asset];
}
// Event to log the updated price of an asset.
event PriceUpdated(string indexed asset, uint price);
}