What is Nostr?
doutorcaleb / Dr. Caleb Isaac
npub178k…aay5
2024-05-22 00:48:25

doutorcaleb on Nostr: with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use ...

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Calendar; use Ada.Calendar;

procedure Main is

package Float_IO is new Ada.Text_IO.Float_IO (Num => Float);
package Unbounded_IO is new Ada.Text_IO.Text_IO (Text => Unbounded_String);

type Party is record
Name : Unbounded_String;
Address : Unbounded_String;
end record;

type Oracle is tagged null record;

type DLC_Contract is tagged record
Party1 : Party;
Party2 : Party;
Bet_Amount : Float;
The_Oracle : Oracle;
Price_At_Contract : Float;
Settlement_Date : Ada.Calendar.Time;
end record;

function Get_Bitcoin_Price (O : Oracle; Date : Ada.Calendar.Time) return Float is
begin
return 40000.0;
end Get_Bitcoin_Price;

procedure Settle_Contract (Contract : in out DLC_Contract) is
Current_Price : Float;
begin
Current_Price := Get_Bitcoin_Price (Contract.The_Oracle, Contract.Settlement_Date);
pragma Assert (Current_Price >= 0.0);
if Current_Price > Contract.Price_At_Contract then
Unbounded_IO.Put (http://Contract.Party1.Name & " wins the bet of " & Float'Image (http://Contract.Bet_Amount) & " BTC");
else
Unbounded_IO.Put (http://Contract.Party2.Name & " wins the bet of " & Float'Image (http://Contract.Bet_Amount) & " BTC");
end if;
end Settle_Contract;

function To_Time (Date : String) return Ada.Calendar.Time is
Year : Integer := Integer'Value (Date (1 .. 4));
Month : Integer := Integer'Value (Date (6 .. 7));
Day : Integer := Integer'Value (Date (9 .. 10));
begin
pragma Assert (Month >= 1 and Month <= 12);
pragma Assert (Day >= 1 and Day <= 31);
return Ada.Calendar.Time_Of (Year, Ada.Calendar.Month (Month), Day);
end To_Time;

Alice, Bob : Party;
Oracle_Instance : Oracle;
Contract : DLC_Contract;

begin
http://Alice.Name := To_Unbounded_String ("Alice");
Alice.Address := To_Unbounded_String ("1AliceAddress");
http://Bob.Name := To_Unbounded_String ("Bob");
Bob.Address := To_Unbounded_String ("1BobAddress");

Contract.Party1 := Alice;
Contract.Party2 := Bob;
http://Contract.Bet_Amount := 1.0;
Contract.The_Oracle := Oracle_Instance;
Contract.Price_At_Contract := 35000.0;
Contract.Settlement_Date := To_Time ("2024-05-28");

Settle_Contract (Contract);
end Main;
Author Public Key
npub178k6vvt0760wmf9lffrjpv2846973ev4flqdkn7jy89ur2huc4qqazaay5