- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlScript.sql
More file actions
Latest commit
200 lines (156 loc) · 4.12 KB
/
Copy pathSqlScript.sql
File metadata and controls
200 lines (156 loc) · 4.12 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
SETANSI_NULLSON
GO
SETQUOTED_IDENTIFIERON
GO
CREATETABLE [dbo].[OutTransactions](
[TxId] [nvarchar](120) NOTNULL,
[Amount] [decimal](18, 9) NOTNULL,
[Address] [nvarchar](120) NOTNULL,
[TimeReceived] [datetime] NOTNULL,
[Confirmations] [int] NOTNULL,
[FromWallet] [nvarchar](50) NOTNULL,
CONSTRAINT [PK_OutTransactions] PRIMARYKEYCLUSTERED
(
[TxId] ASC
)WITH (PAD_INDEX=OFF, STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATETABLE [dbo].[InTransactions](
[TxId] [nvarchar](120) NOTNULL,
[Amount] [decimal](18, 9) NOTNULL,
[Address] [nvarchar](120) NOTNULL,
[TimeReceived] [datetime] NOTNULL,
[Confirmations] [int] NOTNULL,
[IsNew] [bit] NOTNULL,
CONSTRAINT [PK_InTransactions] PRIMARYKEYCLUSTERED
(
[TxId] ASC
)WITH (PAD_INDEX=OFF, STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTERTABLE [dbo].[InTransactions] ADDCONSTRAINT [DF_InTransactions_IsNew] DEFAULT ((1)) FOR [IsNew]
GO
CREATETABLE [dbo].[Wallets](
[Name] [nvarchar](50) NOTNULL,
[Balance] [decimal](18, 9) NOTNULL,
CONSTRAINT [PK_Wallets] PRIMARYKEYCLUSTERED
(
[Name] ASC
)WITH (PAD_INDEX=OFF, STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATEPROCEDURE [dbo].[InTransactions_GetLast]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SETNOCOUNTON;
SELECT [TxId]
,[Amount]
,[Address]
,[TimeReceived]
,[Confirmations]
FROM [InTransactions]
WHERE IsNew =1OR Confirmations <3
update [InTransactions] set IsNew =0
END
GO
CREATEPROCEDURE [dbo].[InTransactions_Store]
-- Add the parameters for the stored procedure here
@TxId nvarchar(120),
@Amount [decimal](18, 9),
@Address [nvarchar](120),
@TimeReceived DATETIME,
@Confirmations [int]
AS
BEGIN
ifexists (select*from InTransactions where TxId = @TxId)
begin
update InTransactions set Confirmations = @Confirmations where TxId = @TxId
end
else
begin
insertinto InTransactions (TxId, Amount, Address, TimeReceived, Confirmations)
values (@TxId, @Amount, @Address, @TimeReceived, @Confirmations)
end
END
GO
CREATEPROCEDURE [dbo].[OutTransactions_Store]
-- Add the parameters for the stored procedure here
@TxId nvarchar(120),
@Amount [decimal](18, 9),
@Address [nvarchar](120),
@TimeReceived DATETIME,
@FromWallet nvarchar(50),
@Confirmations [int]
AS
BEGIN
ifexists (select*from OutTransactions where TxId = @TxId)
begin
update OutTransactions set Confirmations = @Confirmations where TxId = @TxId
end
else
begin
insertinto OutTransactions (TxId, Amount, Address, TimeReceived, Confirmations, FromWallet)
values (@TxId, @Amount, @Address, @TimeReceived, @Confirmations, @FromWallet)
end
END
GO
CREATEPROCEDURE [dbo].[Wallet_Store]
-- Add the parameters for the stored procedure here
@Name nvarchar(50),
@Balance [decimal](18, 9)
AS
BEGIN
ifexists (select*from Wallets whereName= @Name)
begin
update Wallets set Balance = @Balance whereName= @Name
end
else
begin
insertinto Wallets (Name, Balance)
values (@Name, @Balance)
end
END
GO
CREATEPROCEDURE [dbo].[Wallets_GetAll]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SETNOCOUNTON;
SELECT [Name]
,[Balance]
FROM Wallets
END
GO
CREATEPROCEDURE [dbo].[InTransactions_GetNeedToUpdate]
AS
BEGIN
SETNOCOUNTON;
SELECT [TxId]
FROM [InTransactions]
where Confirmations <=6
END
GO
CREATEPROCEDURE [dbo].[OutTransactions_GetLastTransactionDate]
AS
BEGIN
SETNOCOUNTON;
SELECTtop1 TimeReceived
FROM OutTransactions
order by TimeReceived desc
END
CreatePROCEDURE [dbo].[Wallets_ForTransaction]
@Amount [decimal](18, 9)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SETNOCOUNTON;
SELECT [Name]
,[Balance]
FROM Wallets
where Balance > @Amount
END
GO