Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dunixir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
teaching
dunixir
Commits
83c05d00
Commit
83c05d00
authored
3 years ago
by
ABDELGHANI Nassim
Committed by
ABDELGHANI Nassim
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
check size before checking transaction rules
parent
69a9c2cb
No related branches found
No related tags found
1 merge request
!46
Resolve "Validation locale"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/index/index_rules.ex
+63
-54
63 additions, 54 deletions
lib/index/index_rules.ex
with
63 additions
and
54 deletions
lib/index/index_rules.ex
+
63
−
54
View file @
83c05d00
...
...
@@ -36,62 +36,67 @@ defmodule IndexRules do
# Rule: For each OutputBase:
# if BaseDelta > 0, then it must be inferior or equal to the sum of all preceding BaseDelta
# Rule: The sum of all inputs in CommonBase must equal the sum of all outputs in CommonBase
commonBase
=
:ets
.
match
(
local_sindex
,
{
:_
,
%{
base:
:"$1"
}})
|>
Enum
.
map
(
fn
[
base
]
->
String
.
to_integer
(
base
)
end
)
|>
Enum
.
min
()
if
:ets
.
info
(
local_sindex
)[
:size
]
>
0
do
commonBase
=
:ets
.
match
(
local_sindex
,
{
:_
,
%{
base:
:"$1"
}})
|>
IO
.
inspect
()
|>
Enum
.
map
(
fn
[
base
]
->
String
.
to_integer
(
base
)
end
)
|>
Enum
.
min
()
[
inputSumCommonBase
,
outputSumCommonBase
]
=
:ets
.
match
(
local_sindex
,
{
:_
,
%{
amount:
:"$1"
,
base:
:"$2"
,
op:
:"$3"
}})
|>
Enum
.
reduce
([
0
,
0
],
fn
[
amount
,
base
,
op
],
[
inputSumCommonBase
,
outputSumCommonBase
]
->
amountCommonBase
=
String
.
to_integer
(
amount
)
*
Integer
.
pow
(
10
,
String
.
to_integer
(
base
)
-
commonBase
)
[
inputSumCommonBase
,
outputSumCommonBase
]
=
:ets
.
match
(
local_sindex
,
{
:_
,
%{
amount:
:"$1"
,
base:
:"$2"
,
op:
:"$3"
}})
|>
Enum
.
reduce
([
0
,
0
],
fn
[
amount
,
base
,
op
],
[
inputSumCommonBase
,
outputSumCommonBase
]
->
amountCommonBase
=
String
.
to_integer
(
amount
)
*
Integer
.
pow
(
10
,
String
.
to_integer
(
base
)
-
commonBase
)
if
op
==
"CREATE"
do
# output
[
inputSumCommonBase
,
outputSumCommonBase
+
amountCommonBase
]
else
# input
[
inputSumCommonBase
+
amountCommonBase
,
outputSumCommonBase
]
end
end
)
if
op
==
"CREATE"
do
# output
[
inputSumCommonBase
,
outputSumCommonBase
+
amountCommonBase
]
else
# input
[
inputSumCommonBase
+
amountCommonBase
,
outputSumCommonBase
]
end
end
)
if
inputSumCommonBase
==
outputSumCommonBase
do
allBases
=
:ets
.
match
(
local_sindex
,
{
:_
,
%{
base:
:"$1"
}})
|>
Enum
.
map
(
fn
[
base
]
->
String
.
to_integer
(
base
)
end
)
|>
Enum
.
sort
()
|>
Enum
.
uniq
()
if
inputSumCommonBase
==
outputSumCommonBase
do
allBases
=
:ets
.
match
(
local_sindex
,
{
:_
,
%{
base:
:"$1"
}})
|>
Enum
.
map
(
fn
[
base
]
->
String
.
to_integer
(
base
)
end
)
|>
Enum
.
sort
()
|>
Enum
.
uniq
()
allBases
|>
Enum
.
reduce_while
(
0
,
fn
base
,
sumBaseDelta
->
[
inputBaseSum
,
outputBaseSum
]
=
:ets
.
match
(
local_sindex
,
{
:_
,
%{
amount:
:"$1"
,
base:
"
#{
base
}
"
,
op:
:"$2"
}})
|>
Enum
.
reduce
([
0
,
0
],
fn
[
amount
,
op
],
[
inputBaseSum
,
outputBaseSum
]
->
if
op
==
"CREATE"
do
# output
[
inputBaseSum
,
outputBaseSum
+
String
.
to_integer
(
amount
)]
else
# input
[
inputBaseSum
+
String
.
to_integer
(
amount
),
outputBaseSum
]
end
end
)
allBases
|>
Enum
.
reduce_while
(
0
,
fn
base
,
sumBaseDelta
->
[
inputBaseSum
,
outputBaseSum
]
=
:ets
.
match
(
local_sindex
,
{
:_
,
%{
amount:
:"$1"
,
base:
"
#{
base
}
"
,
op:
:"$2"
}})
|>
Enum
.
reduce
([
0
,
0
],
fn
[
amount
,
op
],
[
inputBaseSum
,
outputBaseSum
]
->
if
op
==
"CREATE"
do
# output
[
inputBaseSum
,
outputBaseSum
+
String
.
to_integer
(
amount
)]
else
# input
[
inputBaseSum
+
String
.
to_integer
(
amount
),
outputBaseSum
]
end
end
)
baseDelta
=
outputBaseSum
-
inputBaseSum
baseDelta
=
outputBaseSum
-
inputBaseSum
if
baseDelta
>
0
and
baseDelta
>
-
sumBaseDelta
do
# Functionally: also, we cannot convert a superiod unit base into a lower one.
{
:halt
,
false
}
else
{
:cont
,
sumBaseDelta
+
baseDelta
}
end
end
)
# enforce boolean return
|>
then
(
fn
check_base_delta
->
if
check_base_delta
==
false
,
do
:
false
,
else
:
true
end
)
if
baseDelta
>
0
and
baseDelta
>
-
sumBaseDelta
do
# Functionally: also, we cannot convert a superiod unit base into a lower one.
{
:halt
,
false
}
else
{
:cont
,
sumBaseDelta
+
baseDelta
}
end
end
)
# enforce boolean return
|>
then
(
fn
check_base_delta
->
if
check_base_delta
==
false
,
do
:
false
,
else
:
true
end
)
else
false
end
else
fals
e
tru
e
end
end
...
...
@@ -119,11 +124,15 @@ defmodule IndexRules do
end
defp
checkMaxTransactionChainingDepth
(
local_sindex
)
do
:ets
.
match
(
local_sindex
,
{
:_
,
%{
tx:
:"$1"
}})
|>
Enum
.
map
(
fn
[
txHash
]
->
txHash
end
)
|>
Enum
.
uniq
()
|>
Enum
.
map
(
fn
txHash
->
getTransactionDepth
(
local_sindex
,
txHash
,
0
)
end
)
|>
Enum
.
max
()
<=
5
if
:ets
.
info
(
local_sindex
)[
:size
]
>
0
do
:ets
.
match
(
local_sindex
,
{
:_
,
%{
tx:
:"$1"
}})
|>
Enum
.
map
(
fn
[
txHash
]
->
txHash
end
)
|>
Enum
.
uniq
()
|>
Enum
.
map
(
fn
txHash
->
getTransactionDepth
(
local_sindex
,
txHash
,
0
)
end
)
|>
Enum
.
max
()
<=
5
else
true
end
end
def
check
(
local_iindex
,
local_mindex
,
local_cindex
,
local_sindex
)
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment