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
09f82031
Commit
09f82031
authored
Apr 03, 2018
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor & clean up code a bit
parent
f5196f9e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
147 deletions
+107
-147
provider.js
src/provider.js
+12
-147
txProcess.js
src/txProcess.js
+95
-0
No files found.
src/provider.js
View file @
09f82031
var
Web3
=
require
(
'web3'
)
var
Web3
=
require
(
'web3'
)
var
utils
=
require
(
'ethereumjs-util'
)
var
utils
=
require
(
'ethereumjs-util'
)
var
RemixLib
=
require
(
'remix-lib'
)
var
RemixLib
=
require
(
'remix-lib'
)
var
TxExecution
=
RemixLib
.
execution
.
txExecution
var
TxRunner
=
RemixLib
.
execution
.
txRunner
var
executionContext
=
RemixLib
.
execution
.
executionContext
var
executionContext
=
RemixLib
.
execution
.
executionContext
function
jsonRPCResponse
(
id
,
result
)
{
var
processTx
=
require
(
'./txProcess.js'
)
let
json
=
{
"id"
:
id
,
"jsonrpc"
:
"2.0"
,
"result"
:
result
};
console
.
dir
(
"== response"
);
console
.
dir
(
json
);
return
json
;
}
// TODO: fix me; this is a temporary and very hackish thing just to get the getCode working for now
var
deployedContracts
=
{
}
function
processTx
(
accounts
,
payload
,
isCall
,
callback
)
{
let
api
=
{
logMessage
:
(
msg
)
=>
{
//self._components.editorpanel.log({ type: 'log', value: msg })
},
logHtmlMessage
:
(
msg
)
=>
{
//self._components.editorpanel.log({ type: 'html', value: msg })
},
//config: self._api.config,
config
:
{
getUnpersistedProperty
:
(
key
)
=>
{
console
.
dir
(
"== getUnpersistedProperty =="
)
console
.
dir
(
key
)
if
(
key
===
'settings/always-use-vm'
)
{
return
true
}
return
true
},
get
:
()
=>
{
return
true
}
},
detectNetwork
:
(
cb
)
=>
{
//executionContext.detectNetwork(cb)
cb
()
},
personalMode
:
()
=>
{
//return self._api.config.get('settings/personal-mode')
return
false
}
}
executionContext
.
init
(
api
.
config
);
//console.dir(accounts);
let
txRunner
=
new
TxRunner
(
accounts
,
api
);
if
(
payload
.
params
[
0
].
to
)
{
console
.
log
(
"== processing transaction"
);
// tx
let
from
=
payload
.
params
[
0
].
from
;
let
to
=
payload
.
params
[
0
].
to
;
let
data
=
payload
.
params
[
0
].
data
;
let
value
=
payload
.
params
[
0
].
value
;
let
gasLimit
=
payload
.
params
[
0
].
gasLimit
||
800000
;
let
callbacks
=
{
confirmationCb
:
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
console
.
dir
(
"confirmationCb"
);
continueTxExecution
(
null
);
},
gasEstimationForceSend
:
(
error
,
continueTxExecution
,
cancelCb
)
=>
{
console
.
dir
(
"gasEstimationForceSend"
);
continueTxExecution
();
},
promptCb
:
(
okCb
,
cancelCb
)
=>
{
console
.
dir
(
"promptCb"
);
okCb
();
}
}
let
finalCallback
=
function
(
err
,
result
)
{
console
.
dir
(
arguments
)
console
.
log
(
"called final callback"
)
let
toReturn
;
function
jsonRPCResponse
(
id
,
result
)
{
if
(
isCall
)
{
return
{
"id"
:
id
,
"jsonrpc"
:
"2.0"
,
"result"
:
result
};
console
.
dir
(
result
.
result
.
vm
.
return
);
toReturn
=
"0x"
+
result
.
result
.
vm
.
return
.
toString
(
'hex'
)
if
(
toReturn
===
'0x'
)
{
toReturn
=
'0x0'
}
}
else
{
toReturn
=
result
.
transactionHash
}
console
.
dir
(
"isCall is "
+
isCall
);
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
toReturn
))
}
TxExecution
.
callFunction
(
from
,
to
,
data
,
value
,
gasLimit
,
null
,
txRunner
,
callbacks
,
finalCallback
)
}
else
{
console
.
dir
(
"== contract creation"
);
// contract creation
let
from
=
payload
.
params
[
0
].
from
;
let
data
=
payload
.
params
[
0
].
data
;
let
value
=
payload
.
params
[
0
].
value
;
let
gasLimit
=
payload
.
params
[
0
].
gasLimit
||
800000
;
let
callbacks
=
{
confirmationCb
:
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
console
.
dir
(
"confirmationCb"
);
continueTxExecution
(
null
);
},
gasEstimationForceSend
:
(
error
,
continueTxExecution
,
cancelCb
)
=>
{
console
.
dir
(
"gasEstimationForceSend"
);
continueTxExecution
();
},
promptCb
:
(
okCb
,
cancelCb
)
=>
{
console
.
dir
(
"promptCb"
);
okCb
();
}
}
let
finalCallback
=
function
(
err
,
result
)
{
console
.
dir
(
arguments
)
console
.
log
(
"called final callback"
)
console
.
dir
(
result
)
let
contractAddress
=
(
'0x'
+
result
.
result
.
createdAddress
.
toString
(
'hex'
))
//console.dir(contractAddress)
console
.
dir
(
result
.
transactionHash
)
// TODO: fix me; this is a temporary and very hackish thing just to get the receipts working for now
// deployedContracts[contractAddress] = contractAddress;
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
result
.
transactionHash
))
}
TxExecution
.
createContract
(
from
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
finalCallback
);
}
}
}
Provider
=
function
()
{
Provider
=
function
()
{
this
.
web3
=
new
Web3
();
this
.
web3
=
new
Web3
();
// TODO: make it random
this
.
accounts
=
[
this
.
web3
.
eth
.
accounts
.
create
([
"abcd"
])]
this
.
accounts
=
[
this
.
web3
.
eth
.
accounts
.
create
([
"abcd"
])]
this
.
accounts
[
this
.
accounts
[
0
].
address
.
toLowerCase
()]
=
this
.
accounts
[
0
];
this
.
accounts
[
this
.
accounts
[
0
].
address
.
toLowerCase
()]
=
this
.
accounts
[
0
];
//_accounts[this.accounts[0].address.toLowerCase()].privateKey = Buffer(_accounts[this.accounts[0].address.toLowerCase()].privateKey);
this
.
accounts
[
this
.
accounts
[
0
].
address
.
toLowerCase
()].
privateKey
=
Buffer
.
from
(
this
.
accounts
[
this
.
accounts
[
0
].
address
.
toLowerCase
()].
privateKey
.
slice
(
2
),
'hex'
);
this
.
accounts
[
this
.
accounts
[
0
].
address
.
toLowerCase
()].
privateKey
=
Buffer
.
from
(
this
.
accounts
[
this
.
accounts
[
0
].
address
.
toLowerCase
()].
privateKey
.
slice
(
2
),
'hex'
);
}
//Provider.prototype.send = function(payload) {
// TODO: fix me; this is a temporary and very hackish thing just to get the getCode working for now
// console.log("=========== send");
this
.
deployedContracts
=
{};
// console.dir(payload);
}
// //return this.manager.request(payload);
//}
Provider
.
prototype
.
sendAsync
=
function
(
payload
,
callback
)
{
Provider
.
prototype
.
sendAsync
=
function
(
payload
,
callback
)
{
console
.
log
(
"=========== sendAsync"
);
const
self
=
this
;
console
.
dir
(
payload
);
//console.log("=========== sendAsync");
//console.dir(payload);
if
(
payload
.
method
===
'eth_accounts'
)
{
if
(
payload
.
method
===
'eth_accounts'
)
{
return
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
this
.
accounts
.
map
((
x
)
=>
x
.
address
)))
return
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
this
.
accounts
.
map
((
x
)
=>
x
.
address
)))
}
}
if
(
payload
.
method
===
'eth_estimateGas'
)
{
if
(
payload
.
method
===
'eth_estimateGas'
)
{
//return callback(null, jsonRPCResponseutils.bufferToInt(this.web3.utils.toHex(800000)))
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
800000
))
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
800000
))
}
}
if
(
payload
.
method
===
'eth_gasPrice'
)
{
if
(
payload
.
method
===
'eth_gasPrice'
)
{
//return callback(null, jsonRPCResponseutils.bufferToInt(this.web3.utils.toHex(800000)))
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
1
))
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
1
))
}
}
if
(
payload
.
method
===
'eth_sendTransaction'
)
{
if
(
payload
.
method
===
'eth_sendTransaction'
)
{
...
@@ -173,8 +40,7 @@ Provider.prototype.sendAsync = function(payload, callback) {
...
@@ -173,8 +40,7 @@ Provider.prototype.sendAsync = function(payload, callback) {
}
}
if
(
payload
.
method
===
'eth_getTransactionReceipt'
)
{
if
(
payload
.
method
===
'eth_getTransactionReceipt'
)
{
executionContext
.
web3
().
eth
.
getTransactionReceipt
(
payload
.
params
[
0
],
(
error
,
receipt
)
=>
{
executionContext
.
web3
().
eth
.
getTransactionReceipt
(
payload
.
params
[
0
],
(
error
,
receipt
)
=>
{
//console.dir(receipt);
self
.
deployedContracts
[
receipt
.
contractAddress
]
=
receipt
.
data
deployedContracts
[
receipt
.
contractAddress
]
=
receipt
.
data
var
r
=
{
var
r
=
{
"transactionHash"
:
receipt
.
hash
,
"transactionHash"
:
receipt
.
hash
,
...
@@ -195,12 +61,11 @@ Provider.prototype.sendAsync = function(payload, callback) {
...
@@ -195,12 +61,11 @@ Provider.prototype.sendAsync = function(payload, callback) {
let
address
=
payload
.
params
[
0
];
let
address
=
payload
.
params
[
0
];
let
block
=
payload
.
params
[
1
];
let
block
=
payload
.
params
[
1
];
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
deployedContracts
[
address
]));
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
self
.
deployedContracts
[
address
]));
}
}
if
(
payload
.
method
===
'eth_call'
)
{
if
(
payload
.
method
===
'eth_call'
)
{
processTx
(
this
.
accounts
,
payload
,
true
,
callback
)
processTx
(
this
.
accounts
,
payload
,
true
,
callback
)
}
}
//return this.manager.request(payload, callback);
}
}
Provider
.
prototype
.
isConnected
=
function
()
{
Provider
.
prototype
.
isConnected
=
function
()
{
...
...
src/txProcess.js
0 → 100644
View file @
09f82031
var
RemixLib
=
require
(
'remix-lib'
)
var
TxExecution
=
RemixLib
.
execution
.
txExecution
var
TxRunner
=
RemixLib
.
execution
.
txRunner
var
executionContext
=
RemixLib
.
execution
.
executionContext
function
jsonRPCResponse
(
id
,
result
)
{
return
{
"id"
:
id
,
"jsonrpc"
:
"2.0"
,
"result"
:
result
};
}
function
runTx
(
payload
,
from
,
to
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
isCall
,
callback
)
{
console
.
log
(
'-- runTx'
);
let
finalCallback
=
function
(
err
,
result
)
{
let
toReturn
;
if
(
isCall
)
{
console
.
dir
(
result
.
result
.
vm
.
return
);
console
.
dir
(
result
.
result
.
vm
);
toReturn
=
"0x"
+
result
.
result
.
vm
.
return
.
toString
(
'hex'
)
if
(
toReturn
===
'0x'
)
{
toReturn
=
'0x0'
}
}
else
{
toReturn
=
result
.
transactionHash
}
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
toReturn
))
}
TxExecution
.
callFunction
(
from
,
to
,
data
,
value
,
gasLimit
,
null
,
txRunner
,
callbacks
,
finalCallback
)
}
function
createContract
(
payload
,
from
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
callback
)
{
console
.
log
(
'-- createContract'
);
console
.
dir
(
arguments
);
let
finalCallback
=
function
(
err
,
result
)
{
let
contractAddress
=
(
'0x'
+
result
.
result
.
createdAddress
.
toString
(
'hex'
))
callback
(
null
,
jsonRPCResponse
(
payload
.
id
,
result
.
transactionHash
))
}
TxExecution
.
createContract
(
from
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
finalCallback
);
}
function
processTx
(
accounts
,
payload
,
isCall
,
callback
)
{
console
.
log
(
'-- processTx'
);
let
api
=
{
logMessage
:
(
msg
)
=>
{
},
logHtmlMessage
:
(
msg
)
=>
{
},
//config: self._api.config,
config
:
{
getUnpersistedProperty
:
(
key
)
=>
{
//if (key === 'settings/always-use-vm') {
// return true
//}
return
true
},
get
:
()
=>
{
return
true
}
},
detectNetwork
:
(
cb
)
=>
{
cb
()
},
personalMode
:
()
=>
{
//return self._api.config.get('settings/personal-mode')
return
false
}
}
executionContext
.
init
(
api
.
config
);
let
txRunner
=
new
TxRunner
(
accounts
,
api
);
let
{
from
:
from
,
to
:
to
,
data
:
data
,
value
:
value
,
gasLimit
:
gasLimit
}
=
payload
.
params
[
0
];
gasLimit
=
gasLimit
||
800000
;
let
callbacks
=
{
confirmationCb
:
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
continueTxExecution
(
null
);
},
gasEstimationForceSend
:
(
error
,
continueTxExecution
,
cancelCb
)
=>
{
continueTxExecution
();
},
promptCb
:
(
okCb
,
cancelCb
)
=>
{
okCb
();
}
}
if
(
to
)
{
runTx
(
payload
,
from
,
to
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
isCall
,
callback
);
}
else
{
createContract
(
payload
,
from
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
callback
);
}
}
module
.
exports
=
processTx
;
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