Reputation: 117
I am approaching blockchain and smart contracts for the first time and I have trouble understanding some concepts. I have to design a decision making architecture based on smart contracts. I have to manage hotel reservations based on the weather. The weather information is provided by the oracle. After the oracle has collected the weather data what happens? Is there an oracle smart contract that communicates with my smart contract?
Upvotes: 2
Views: 471
Reputation: 19
Yes, typically there would be an oracle smart contract that communicates with your smart contract to provide the weather information. Oracles are third-party services that provide external data to smart contracts on the blockchain, and they are often used to trigger smart contract actions based on real-world events.
In your case, the oracle would collect weather data and send it to the oracle smart contract. The oracle smart contract would then take the weather data, process it, and send it to your smart contract. Your smart contract would then use the weather data to make a decision on hotel reservations based on your decision making architecture.
The communication between the oracle smart contract and your smart contract would typically be done through a function call or an event. Your smart contract would define a function or event that the oracle smart contract can call to provide the weather data. The oracle smart contract would then call this function or emit this event to provide the weather data to your smart contract.
It's important to note that the oracle smart contract and the oracle service itself must be trusted to provide accurate and timely data. Therefore, it's essential to thoroughly vet the oracle service and the oracle smart contract to ensure that they are secure and reliable before integrating them into your decision making architecture.
Upvotes: -1
Reputation: 1249
Here I will schematically describe a variant with the transmission of an event to a oracle. The corresponding smart contracts are listed at the end. The sequence of actions is as follows:
pragma solidity >=0.5.8 <0.6.0;
contract Booking
{
Weather WeatherAddr=0x00 ; // Address of contract Weather
struct Request
{
bytes32 Location ;
bytes32 Attr1 ;
int256 Attr2 ;
}
mapping (bytes32 => Request) Requests ;
constructor() public
{
}
function BookRequest(bytes32 id_, bytes32 location_, bytes32 attr1, int256 attr2) public payable
{
bool result ;
Requests[id_]=Request({ Location: location_,
Attr1: attr1,
Attr2: attr2 }) ;
(result,)=address(WeatherAddr).call.gas(0x300000).value(msg.value)(abi.encodeWithSignature("GetWetaher(bytes32,bytes32)", id_, location_)) ;
if(result==false) require(false) ;
}
function CallBack(bytes32 id_, int256 tempirature_) public
{
// 1. Restore request context from Requests[id_]
// 2. Process request for booking
}
}
contract Weather
{
address Owner ;
uint256 Value ;
event RequestWeather(address booking, bytes32 id, bytes32 location) ;
constructor() public
{
Owner=tx.origin ;
}
function GetWeather(bytes32 id_, bytes32 location_) public payable
{
Value+=msg.value ;
emit RequestWeather(msg.sender, id_, location_) ;
}
function SendMoneyOwner() public
{
bool result ;
(result,)=Owner.call.gas(0x30000).value(Value)("") ;
if(result==false) require(false) ;
Value=0 ;
}
}
Upvotes: 1
Reputation: 1249
If you want to use Ethereum, the easiest way is to call the oracle some view-method from your smart contract and get the required data. An example is shown below.
pragma solidity >=0.5.8 <0.6.0;
contract Booking
{
Weather WeatherAddr ;
constructor() public
{
}
function AnyFunction(bytes32 place_) public
{
int256 Conditions ;
int256 Temperature ;
(Conditions, Temperature)=WeatherAddr.GetWeather(place_) ;
// ...
}
}
contract Weather
{
struct PlaceWeather
{
int256 Temperature ;
int256 Conditions ;
}
mapping (bytes32 => PlaceWeather) Places ;
constructor() public
{
}
function GetWeather(bytes32 place_) public view returns (int256, int256 retVal)
{
return(Places[place_].Conditions, Places[place_].Temperature) ;
}
}
Upvotes: 1