-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbitcoin_like-transaction_outputs.adb
78 lines (63 loc) · 2.51 KB
/
bitcoin_like-transaction_outputs.adb
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- Copyright (C) 2019-2020 Dmitry Petukhov https://github.com/dgpv
--
-- This file is part of spark-bitcoin-transaction-example
--
-- It is subject to the license terms in the LICENSE file found in the top-level
-- directory of this distribution.
--
-- No part of spark-bitcoin-transaction-example, including this file, may be copied, modified,
-- propagated, or distributed except according to the terms contained in the
-- LICENSE file.
pragma SPARK_Mode(On);
package body Bitcoin_Like.Transaction_Outputs is
procedure Deserialize(Output: out Output_Type) is
use Data_Checkpoints;
U64_Value: Unsigned_Modular_Int64;
Raw_Data_Status_Old: Raw_Data.Status_Type := Raw_Data_Status with Ghost;
Ghost_Data_Tape_Old: Ghost_Data_Tape_Type := Ghost_Data_Tape with Ghost;
begin
Data_Checkpoint(Tag_Output_Value);
Data_Readers.Read_Unsigned_64(U64_Value);
if Got_Error then
Output := Empty_Output;
return;
end if;
if U64_Value > Unsigned_Modular_Int64(Satoshi_Type'Last) then
Register_Structural_Error(
"Encountered an output with a value " & Unsigned_Modular_Int64'Image(U64_Value)
& " that is larger than allowed by consensus rules (" & Satoshi_Type'Image(Satoshi_Type'Last) & ")"
);
Output := Empty_Output;
return;
end if;
Output.Value := Satoshi_Type(U64_Value);
Data_Checkpoint(Tag_Pubkey_Script);
Scripts.Deserialize(Output.Pubkey_Script);
if Got_Error then
Output := Empty_Output;
return;
end if;
Data_Checkpoint_Final;
pragma Assert (
Data_Readers.Unsigned64_Ghost_Tape_Match(
Unsigned_Modular_Int64(Output.Value),
Data_Checkpoints.Checkpoint_States.Ghost_Tape_Position(
Tag_Output_Value, Data_Checkpoints.State))
);
pragma Assert (
Scripts.Script_Ghost_Tape_Match(
Output.Pubkey_Script,
Data_Checkpoints.Checkpoint_States.Ghost_Tape_Position(
Tag_Pubkey_Script, Data_Checkpoints.State))
);
pragma Assert (Output_Ghost_Tape_Match(Output, Bytes_Processed_With(Raw_Data_Status_Old)));
pragma Assert (
for all I in Ghost_Data_Tape'Range => (
if (I < Bytes_Processed_With(Raw_Data_Status_Old)
or I >= Bytes_Processed_With(Raw_Data_Status_Old)
+ Natural(Output_Serialized_Data_Length(Output)))
then Ghost_Data_Tape(I) = Ghost_Data_Tape_Old(I)
)
);
end Deserialize;
end Bitcoin_Like.Transaction_Outputs;