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
168d44ca
Unverified
Commit
168d44ca
authored
Feb 12, 2018
by
yann300
Committed by
GitHub
Feb 12, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1041 from ethereum/refactor/udapp_refactor_waterfall
refactor udapp runTx and related functions
parents
a589650c
bc5347ec
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
75 deletions
+43
-75
universal-dapp.js
src/universal-dapp.js
+43
-75
No files found.
src/universal-dapp.js
View file @
168d44ca
/* global */
/* global */
'use strict'
'use strict'
var
async
=
require
(
'async'
)
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
BN
=
ethJSUtil
.
BN
var
BN
=
ethJSUtil
.
BN
var
remixLib
=
require
(
'remix-lib'
)
var
remixLib
=
require
(
'remix-lib'
)
...
@@ -201,99 +202,66 @@ UniversalDApp.prototype.getInputs = function (funABI) {
...
@@ -201,99 +202,66 @@ UniversalDApp.prototype.getInputs = function (funABI) {
return
txHelper
.
inputParametersDeclarationToString
(
funABI
.
inputs
)
return
txHelper
.
inputParametersDeclarationToString
(
funABI
.
inputs
)
}
}
function
execute
(
pipeline
,
env
,
callback
)
{
function
next
(
err
,
env
)
{
if
(
err
)
return
callback
(
err
)
var
step
=
pipeline
.
shift
()
if
(
step
)
step
(
env
,
next
)
else
callback
(
null
,
env
.
result
)
}
next
(
null
,
env
)
}
UniversalDApp
.
prototype
.
runTx
=
function
(
args
,
cb
)
{
UniversalDApp
.
prototype
.
runTx
=
function
(
args
,
cb
)
{
var
self
=
this
const
self
=
this
var
tx
=
{
to
:
args
.
to
,
data
:
args
.
data
.
dataHex
,
useCall
:
args
.
useCall
,
from
:
args
.
from
,
value
:
args
.
value
}
async
.
waterfall
([
var
payLoad
=
{
funAbi
:
args
.
data
.
funAbi
,
funArgs
:
args
.
data
.
funArgs
,
contractBytecode
:
args
.
data
.
contractBytecode
,
contractName
:
args
.
data
.
contractName
}
// contains decoded parameters
function
getGasLimit
(
next
)
{
var
pipeline
=
[
queryGasLimit
]
if
(
!
args
.
value
)
{
pipeline
.
push
(
queryValue
)
}
if
(
!
args
.
from
)
{
pipeline
.
push
(
queryAddress
)
}
pipeline
.
push
(
runTransaction
)
var
env
=
{
self
,
tx
,
payLoad
}
execute
(
pipeline
,
env
,
cb
)
}
function
queryGasLimit
(
env
,
next
)
{
var
{
self
,
tx
}
=
env
tx
.
gasLimit
=
3000000
if
(
self
.
transactionContextAPI
.
getGasLimit
)
{
if
(
self
.
transactionContextAPI
.
getGasLimit
)
{
self
.
transactionContextAPI
.
getGasLimit
(
function
(
err
,
ret
)
{
return
self
.
transactionContextAPI
.
getGasLimit
(
next
)
if
(
err
)
return
next
(
err
)
}
tx
.
gasLimit
=
ret
next
(
null
,
3000000
)
next
(
null
,
env
)
},
})
function
queryValue
(
gasLimit
,
next
)
{
}
else
next
(
null
,
env
)
if
(
args
.
value
)
{
}
return
next
(
null
,
args
.
value
,
gasLimit
)
}
function
queryValue
(
env
,
next
)
{
if
(
args
.
useCall
||
!
self
.
transactionContextAPI
.
getValue
)
{
var
{
self
,
tx
}
=
env
return
next
(
null
,
0
,
gasLimit
)
tx
.
value
=
0
}
if
(
tx
.
useCall
)
return
next
(
null
,
env
)
self
.
transactionContextAPI
.
getValue
(
function
(
err
,
value
)
{
if
(
self
.
transactionContextAPI
.
getValue
)
{
next
(
err
,
value
,
gasLimit
)
self
.
transactionContextAPI
.
getValue
(
function
(
err
,
ret
)
{
if
(
err
)
return
next
(
err
)
tx
.
value
=
ret
next
(
null
,
env
)
})
})
}
else
next
(
null
,
env
)
},
}
function
getAccount
(
value
,
gasLimit
,
next
)
{
if
(
args
.
from
)
{
function
queryAddress
(
env
,
next
)
{
return
next
(
null
,
args
.
from
,
value
,
gasLimit
)
var
{
self
,
tx
}
=
env
}
if
(
self
.
transactionContextAPI
.
getAddress
)
{
if
(
self
.
transactionContextAPI
.
getAddress
)
{
self
.
transactionContextAPI
.
getAddress
(
function
(
err
,
ret
)
{
return
self
.
transactionContextAPI
.
getAddress
(
function
(
err
,
address
)
{
if
(
err
)
return
next
(
err
)
next
(
err
,
address
,
value
,
gasLimit
)
tx
.
from
=
ret
next
(
null
,
env
)
})
})
}
else
{
}
self
.
getAccounts
(
function
(
err
,
ret
)
{
self
.
getAccounts
(
function
(
err
,
accounts
)
{
let
address
=
accounts
[
0
]
if
(
err
)
return
next
(
err
)
if
(
err
)
return
next
(
err
)
if
(
ret
.
length
===
0
)
return
next
(
'No accounts available'
)
if
(
!
address
)
return
next
(
'No accounts available'
)
if
(
executionContext
.
isVM
()
&&
!
self
.
accounts
[
ret
[
0
]
])
{
if
(
executionContext
.
isVM
()
&&
!
self
.
accounts
[
address
])
{
return
next
(
'Invalid account selected'
)
return
next
(
'Invalid account selected'
)
}
}
tx
.
from
=
ret
[
0
]
next
(
null
,
address
,
value
,
gasLimit
)
next
(
null
,
env
)
})
})
}
},
}
function
runTransaction
(
fromAddress
,
value
,
gasLimit
,
next
)
{
var
tx
=
{
to
:
args
.
to
,
data
:
args
.
data
.
dataHex
,
useCall
:
args
.
useCall
,
from
:
fromAddress
,
value
:
value
,
gasLimit
:
gasLimit
}
function
runTransaction
(
env
,
next
)
{
var
payLoad
=
{
funAbi
:
args
.
data
.
funAbi
,
funArgs
:
args
.
data
.
funArgs
,
contractBytecode
:
args
.
data
.
contractBytecode
,
contractName
:
args
.
data
.
contractName
}
var
{
self
,
tx
,
payLoad
}
=
env
var
timestamp
=
Date
.
now
()
var
timestamp
=
Date
.
now
()
self
.
event
.
trigger
(
'initiatingTransaction'
,
[
timestamp
,
tx
,
payLoad
])
self
.
event
.
trigger
(
'initiatingTransaction'
,
[
timestamp
,
tx
,
payLoad
])
self
.
txRunner
.
rawRun
(
tx
,
function
(
error
,
result
)
{
self
.
txRunner
.
rawRun
(
tx
,
function
(
error
,
result
)
{
if
(
!
tx
.
useCall
)
{
let
eventName
=
(
tx
.
useCall
?
'callExecuted'
:
'transactionExecuted'
)
self
.
event
.
trigger
(
'transactionExecuted'
,
[
error
,
tx
.
from
,
tx
.
to
,
tx
.
data
,
false
,
result
,
timestamp
,
payLoad
])
self
.
event
.
trigger
(
eventName
,
[
error
,
tx
.
from
,
tx
.
to
,
tx
.
data
,
tx
.
useCall
,
result
,
timestamp
,
payLoad
])
}
else
{
self
.
event
.
trigger
(
'callExecuted'
,
[
error
,
tx
.
from
,
tx
.
to
,
tx
.
data
,
true
,
result
,
timestamp
,
payLoad
])
if
(
error
&&
(
typeof
(
error
)
!==
'string'
))
{
}
if
(
error
)
{
if
(
typeof
(
error
)
!==
'string'
)
{
if
(
error
.
message
)
error
=
error
.
message
if
(
error
.
message
)
error
=
error
.
message
else
{
else
{
try
{
error
=
'error: '
+
JSON
.
stringify
(
error
)
}
catch
(
e
)
{}
try
{
error
=
'error: '
+
JSON
.
stringify
(
error
)
}
catch
(
e
)
{}
}
}
}
}
}
next
(
error
,
result
)
env
.
result
=
result
next
(
error
,
env
)
})
})
}
],
cb
)
}
}
module
.
exports
=
UniversalDApp
module
.
exports
=
UniversalDApp
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