Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
bbab1f01
Unverified
Commit
bbab1f01
authored
Sep 25, 2019
by
yann300
Committed by
GitHub
Sep 25, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1300 from ethereum/params_parsing
function params parsing improved
parents
e16d5b42
63da6453
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
23 deletions
+47
-23
txFormat.js
remix-lib/src/execution/txFormat.js
+47
-23
txFormat.js
remix-lib/test/txFormat.js
+0
-0
No files found.
remix-lib/src/execution/txFormat.js
View file @
bbab1f01
...
...
@@ -388,36 +388,60 @@ module.exports = {
parseFunctionParams
:
function
(
params
)
{
let
args
=
[]
//
Segregate params textbox string with respect to comma (,)
params
=
params
.
split
(
','
)
//
Check if parameter string starts with array or string
let
startIndex
=
this
.
isArrayOrStringStart
(
params
,
0
)
?
-
1
:
0
for
(
let
i
=
0
;
i
<
params
.
length
;
i
++
)
{
let
param
=
params
[
i
].
trim
()
// Check if param starts with " , it may be string, address etc.
if
(
param
.
charAt
(
0
)
===
'"'
)
{
// Check if param completes in one location by looking for end quote (case: address data type)
if
(
param
.
charAt
(
param
.
length
-
1
)
===
'"'
)
{
args
.
push
(
param
.
slice
(
1
,
param
.
length
-
1
))
}
else
{
let
lastIndex
=
false
let
paramStr
=
param
.
slice
(
1
,
param
.
length
)
// For a paramter got divided in multiple location(case: string data type containing comma(,))
for
(
let
j
=
i
+
1
;
!
lastIndex
;
j
++
)
{
// Check if end quote is reached
if
(
params
[
j
].
charAt
(
params
[
j
].
length
-
1
)
===
'"'
)
{
paramStr
+=
','
+
params
[
j
].
slice
(
0
,
params
[
j
].
length
-
1
)
// If a quote is received
if
(
params
.
charAt
(
i
)
===
'"'
)
{
startIndex
=
-
1
let
endQuoteIndex
=
false
// look for closing quote. On success, push the complete string in arguments list
for
(
let
j
=
i
+
1
;
!
endQuoteIndex
;
j
++
)
{
if
(
params
.
charAt
(
j
)
===
'"'
)
{
args
.
push
(
params
.
substring
(
i
+
1
,
j
))
endQuoteIndex
=
true
i
=
j
args
.
push
(
paramStr
)
lastIndex
=
true
}
else
{
paramStr
+=
','
+
params
[
j
]
}
}
}
}
else
if
(
params
.
charAt
(
i
)
===
'['
)
{
// If a array opening bracket is received
startIndex
=
-
1
let
bracketCount
=
1
let
j
for
(
j
=
i
+
1
;
bracketCount
!==
0
;
j
++
)
{
// Increase count if another array opening bracket is received (To handle nested array)
if
(
params
.
charAt
(
j
)
===
'['
)
{
bracketCount
++
}
else
if
(
params
.
charAt
(
j
)
===
']'
)
{
// // Decrease count if an array closing bracket is received (To handle nested array)
bracketCount
--
}
}
// If bracketCount = 0, it means complete array/nested array parsed, push it to the arguments list
args
.
push
(
JSON
.
parse
(
params
.
substring
(
i
,
j
)))
i
=
j
-
1
}
else
if
(
params
.
charAt
(
i
)
===
','
)
{
// if startIndex >= 0, it means a parameter was being parsed, it can be first or other parameter
if
(
startIndex
>=
0
)
{
args
.
push
(
params
.
substring
(
startIndex
,
i
))
}
// Register start index of a parameter to parse
startIndex
=
this
.
isArrayOrStringStart
(
params
,
i
+
1
)
?
-
1
:
i
+
1
}
else
if
(
startIndex
>=
0
&&
i
===
params
.
length
-
1
)
{
// If start index is registered and string is completed (To handle last parameter)
args
.
push
(
params
.
substring
(
startIndex
,
params
.
length
))
}
}
args
=
args
.
map
(
e
=>
{
if
(
!
Array
.
isArray
(
e
))
{
return
e
.
trim
()
}
else
{
args
.
push
(
param
)
}
return
e
}
})
return
args
},
isArrayOrStringStart
:
function
(
str
,
index
)
{
return
str
.
charAt
(
index
)
===
'"'
||
str
.
charAt
(
index
)
===
'['
}
}
remix-lib/test/txFormat.js
View file @
bbab1f01
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment