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
662faf8c
Commit
662faf8c
authored
Dec 02, 2020
by
aniket-engg
Committed by
Aniket
Dec 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eventManager, storage and universalDapp
parent
34bc1cd6
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
68 deletions
+85
-68
eventManager.ts
libs/remix-lib/src/eventManager.ts
+19
-14
txRunner.ts
libs/remix-lib/src/execution/txRunner.ts
+2
-3
storage.ts
libs/remix-lib/src/storage.ts
+36
-32
universalDapp.ts
libs/remix-lib/src/universalDapp.ts
+28
-19
No files found.
libs/remix-lib/src/eventManager.ts
View file @
662faf8c
'use strict'
'use strict'
function
eventManager
()
{
export
class
EventManager
{
registered
anonymous
constructor
()
{
this
.
registered
=
{}
this
.
registered
=
{}
this
.
anonymous
=
{}
this
.
anonymous
=
{}
}
}
/*
/*
* Unregister a listener.
* Unregister a listener.
* Note that if obj is a function. the unregistration will be applied to the dummy obj {}.
* Note that if obj is a function. the unregistration will be applied to the dummy obj {}.
*
*
* @param {String} eventName - the event name
* @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event
* @param {Object or Func} obj - object that will listen on this event
* @param {Func} func - function of the listeners that will be executed
* @param {Func} func - function of the listeners that will be executed
*/
*/
eventManager
.
prototype
.
unregister
=
function
(
eventName
,
obj
,
func
)
{
unregister
(
eventName
,
obj
,
func
)
{
if
(
!
this
.
registered
[
eventName
])
{
if
(
!
this
.
registered
[
eventName
])
{
return
return
}
}
...
@@ -26,17 +31,17 @@ eventManager.prototype.unregister = function (eventName, obj, func) {
...
@@ -26,17 +31,17 @@ eventManager.prototype.unregister = function (eventName, obj, func) {
this
.
registered
[
eventName
].
splice
(
reg
,
1
)
this
.
registered
[
eventName
].
splice
(
reg
,
1
)
}
}
}
}
}
}
/*
/*
* Register a new listener.
* Register a new listener.
* Note that if obj is a function, the function registration will be associated with the dummy object {}
* Note that if obj is a function, the function registration will be associated with the dummy object {}
*
*
* @param {String} eventName - the event name
* @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event
* @param {Object or Func} obj - object that will listen on this event
* @param {Func} func - function of the listeners that will be executed
* @param {Func} func - function of the listeners that will be executed
*/
*/
eventManager
.
prototype
.
register
=
function
(
eventName
,
obj
,
func
)
{
register
(
eventName
,
obj
,
func
)
{
if
(
!
this
.
registered
[
eventName
])
{
if
(
!
this
.
registered
[
eventName
])
{
this
.
registered
[
eventName
]
=
[]
this
.
registered
[
eventName
]
=
[]
}
}
...
@@ -45,16 +50,16 @@ eventManager.prototype.register = function (eventName, obj, func) {
...
@@ -45,16 +50,16 @@ eventManager.prototype.register = function (eventName, obj, func) {
obj
=
this
.
anonymous
obj
=
this
.
anonymous
}
}
this
.
registered
[
eventName
].
push
({
obj
,
func
})
this
.
registered
[
eventName
].
push
({
obj
,
func
})
}
}
/*
/*
* trigger event.
* trigger event.
* Every listener have their associated function executed
* Every listener have their associated function executed
*
*
* @param {String} eventName - the event name
* @param {String} eventName - the event name
* @param {Array}j - argument that will be passed to the executed function.
* @param {Array}j - argument that will be passed to the executed function.
*/
*/
eventManager
.
prototype
.
trigger
=
function
(
eventName
,
args
)
{
trigger
(
eventName
,
args
)
{
if
(
!
this
.
registered
[
eventName
])
{
if
(
!
this
.
registered
[
eventName
])
{
return
return
}
}
...
@@ -62,6 +67,6 @@ eventManager.prototype.trigger = function (eventName, args) {
...
@@ -62,6 +67,6 @@ eventManager.prototype.trigger = function (eventName, args) {
const
l
=
this
.
registered
[
eventName
][
listener
]
const
l
=
this
.
registered
[
eventName
][
listener
]
l
.
func
.
apply
(
l
.
obj
===
this
.
anonymous
?
{}
:
l
.
obj
,
args
)
l
.
func
.
apply
(
l
.
obj
===
this
.
anonymous
?
{}
:
l
.
obj
,
args
)
}
}
}
}
}
module
.
exports
=
eventManager
libs/remix-lib/src/execution/txRunner.ts
View file @
662faf8c
...
@@ -5,7 +5,7 @@ import { BN, bufferToHex } from 'ethereumjs-util'
...
@@ -5,7 +5,7 @@ import { BN, bufferToHex } from 'ethereumjs-util'
import
{
ExecutionContext
}
from
'./execution-context'
import
{
ExecutionContext
}
from
'./execution-context'
const
EventManager
=
require
(
'../eventManager'
)
const
EventManager
=
require
(
'../eventManager'
)
class
TxRunner
{
export
class
TxRunner
{
event
event
executionContext
executionContext
...
@@ -272,5 +272,3 @@ function run(self, tx, stamp, confirmationCb, gasEstimationForceSend = null, pro
...
@@ -272,5 +272,3 @@ function run(self, tx, stamp, confirmationCb, gasEstimationForceSend = null, pro
}
}
})
})
}
}
\ No newline at end of file
module
.
exports
=
TxRunner
libs/remix-lib/src/storage.ts
View file @
662faf8c
'use strict'
'use strict'
function
Storage
(
prefix
)
{
export
class
Storage
{
this
.
exists
=
function
(
name
)
{
prefix
constructor
(
prefix
)
{
this
.
prefix
=
prefix
// on startup, upgrade the old storage layout
if
(
typeof
window
!==
'undefined'
)
{
this
.
safeKeys
().
forEach
(
function
(
name
)
{
if
(
name
.
indexOf
(
'sol-cache-file-'
,
0
)
===
0
)
{
var
content
=
window
.
localStorage
.
getItem
(
name
)
window
.
localStorage
.
setItem
(
name
.
replace
(
/^sol-cache-file-/
,
'sol:'
),
content
)
window
.
localStorage
.
removeItem
(
name
)
}
})
}
// remove obsolete key
if
(
typeof
window
!==
'undefined'
)
{
window
.
localStorage
.
removeItem
(
'editor-size-cache'
)
}
}
exists
(
name
)
{
if
(
typeof
window
!==
'undefined'
)
{
if
(
typeof
window
!==
'undefined'
)
{
return
this
.
get
(
name
)
!==
null
return
this
.
get
(
name
)
!==
null
}
}
}
}
this
.
get
=
function
(
name
)
{
get
(
name
)
{
if
(
typeof
window
!==
'undefined'
)
{
if
(
typeof
window
!==
'undefined'
)
{
return
window
.
localStorage
.
getItem
(
prefix
+
name
)
return
window
.
localStorage
.
getItem
(
this
.
prefix
+
name
)
}
}
}
}
this
.
set
=
function
(
name
,
content
)
{
set
(
name
,
content
)
{
try
{
try
{
if
(
typeof
window
!==
'undefined'
)
{
if
(
typeof
window
!==
'undefined'
)
{
window
.
localStorage
.
setItem
(
prefix
+
name
,
content
)
window
.
localStorage
.
setItem
(
this
.
prefix
+
name
,
content
)
}
}
}
catch
(
exception
)
{
}
catch
(
exception
)
{
return
false
return
false
...
@@ -24,14 +46,14 @@ function Storage (prefix) {
...
@@ -24,14 +46,14 @@ function Storage (prefix) {
return
true
return
true
}
}
this
.
remove
=
function
(
name
)
{
remove
(
name
)
{
if
(
typeof
window
!==
'undefined'
)
{
if
(
typeof
window
!==
'undefined'
)
{
window
.
localStorage
.
removeItem
(
prefix
+
name
)
window
.
localStorage
.
removeItem
(
this
.
prefix
+
name
)
}
}
return
true
return
true
}
}
this
.
rename
=
function
(
originalName
,
newName
)
{
rename
(
originalName
,
newName
)
{
const
content
=
this
.
get
(
originalName
)
const
content
=
this
.
get
(
originalName
)
if
(
!
this
.
set
(
newName
,
content
))
{
if
(
!
this
.
set
(
newName
,
content
))
{
return
false
return
false
...
@@ -40,7 +62,7 @@ function Storage (prefix) {
...
@@ -40,7 +62,7 @@ function Storage (prefix) {
return
true
return
true
}
}
function
safeKeys
()
{
safeKeys
()
{
// NOTE: this is a workaround for some browsers
// NOTE: this is a workaround for some browsers
if
(
typeof
window
!==
'undefined'
)
{
if
(
typeof
window
!==
'undefined'
)
{
return
Object
.
keys
(
window
.
localStorage
).
filter
(
function
(
item
)
{
return
item
!==
null
&&
item
!==
undefined
})
return
Object
.
keys
(
window
.
localStorage
).
filter
(
function
(
item
)
{
return
item
!==
null
&&
item
!==
undefined
})
...
@@ -48,29 +70,11 @@ function Storage (prefix) {
...
@@ -48,29 +70,11 @@ function Storage (prefix) {
return
[]
return
[]
}
}
this
.
keys
=
function
()
{
keys
()
{
return
safeKeys
()
return
this
.
safeKeys
()
// filter any names not including the prefix
// filter any names not including the prefix
.
filter
(
function
(
item
)
{
return
item
.
indexOf
(
prefix
,
0
)
===
0
})
.
filter
(
function
(
item
)
{
return
item
.
indexOf
(
this
.
prefix
,
0
)
===
0
})
// remove prefix from filename and add the 'browser' path
// remove prefix from filename and add the 'browser' path
.
map
(
function
(
item
)
{
return
item
.
substr
(
prefix
.
length
)
})
.
map
(
function
(
item
)
{
return
item
.
substr
(
this
.
prefix
.
length
)
})
}
// on startup, upgrade the old storage layout
if
(
typeof
window
!==
'undefined'
)
{
safeKeys
().
forEach
(
function
(
name
)
{
if
(
name
.
indexOf
(
'sol-cache-file-'
,
0
)
===
0
)
{
var
content
=
window
.
localStorage
.
getItem
(
name
)
window
.
localStorage
.
setItem
(
name
.
replace
(
/^sol-cache-file-/
,
'sol:'
),
content
)
window
.
localStorage
.
removeItem
(
name
)
}
})
}
// remove obsolete key
if
(
typeof
window
!==
'undefined'
)
{
window
.
localStorage
.
removeItem
(
'editor-size-cache'
)
}
}
}
}
module
.
exports
=
Storage
libs/remix-lib/src/universalDapp.ts
View file @
662faf8c
const
async
=
require
(
'async'
)
import
{
waterfall
}
from
'async'
const
{
BN
,
privateToAddress
,
isValidPrivate
,
stripHexPrefix
,
toChecksumAddress
}
=
require
(
'ethereumjs-util'
)
import
{
BN
,
privateToAddress
,
isValidPrivate
,
toChecksumAddress
}
from
'ethereumjs-util'
const
crypto
=
require
(
'crypto'
)
import
{
stripHexPrefix
}
from
'ethjs-util'
const
{
EventEmitter
}
=
require
(
'events'
)
import
{
randomBytes
}
from
'crypto'
import
{
EventEmitter
}
from
'events'
const
TxRunner
=
require
(
'./execution/txRunner'
)
const
txHelper
=
require
(
'./execution/txHelper'
)
import
{
TxRunner
}
from
'./execution/txRunner'
const
EventManager
=
require
(
'./eventManager'
)
import
{
sortAbiFunction
,
getFallbackInterface
,
getReceiveInterface
,
inputParametersDeclarationToString
}
from
'./execution/txHelper'
const
defaultExecutionContext
=
require
(
'./execution/execution-context'
)
import
{
EventManager
}
from
'./eventManager'
const
{
resultToRemixTx
}
=
require
(
'./helpers/txResultHelper'
)
import
{
ExecutionContext
}
from
'./execution/execution-context'
import
{
resultToRemixTx
}
from
'./helpers/txResultHelper'
module
.
exports
=
class
UniversalDApp
{
export
class
UniversalDApp
{
events
event
executionContext
config
txRunner
accounts
transactionContextAPI
constructor
(
config
,
executionContext
)
{
constructor
(
config
,
executionContext
)
{
this
.
events
=
new
EventEmitter
()
this
.
events
=
new
EventEmitter
()
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
// has a default for now for backwards compatability
// has a default for now for backwards compatability
this
.
executionContext
=
executionContext
||
defaultExecutionContext
this
.
executionContext
=
executionContext
||
new
ExecutionContext
()
this
.
config
=
config
this
.
config
=
config
this
.
txRunner
=
new
TxRunner
({},
{
this
.
txRunner
=
new
TxRunner
({},
{
...
@@ -97,7 +106,7 @@ module.exports = class UniversalDApp {
...
@@ -97,7 +106,7 @@ module.exports = class UniversalDApp {
}
}
let
privateKey
let
privateKey
do
{
do
{
privateKey
=
crypto
.
randomBytes
(
32
)
privateKey
=
randomBytes
(
32
)
}
while
(
!
isValidPrivate
(
privateKey
))
}
while
(
!
isValidPrivate
(
privateKey
))
this
.
_addAccount
(
privateKey
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
privateKey
,
'0x56BC75E2D63100000'
)
cb
(
null
,
'0x'
+
privateToAddress
(
privateKey
).
toString
(
'hex'
))
cb
(
null
,
'0x'
+
privateToAddress
(
privateKey
).
toString
(
'hex'
))
...
@@ -247,22 +256,22 @@ module.exports = class UniversalDApp {
...
@@ -247,22 +256,22 @@ module.exports = class UniversalDApp {
}
}
getABI
(
contract
)
{
getABI
(
contract
)
{
return
txHelper
.
sortAbiFunction
(
contract
.
abi
)
return
sortAbiFunction
(
contract
.
abi
)
}
}
getFallbackInterface
(
contractABI
)
{
getFallbackInterface
(
contractABI
)
{
return
txHelper
.
getFallbackInterface
(
contractABI
)
return
getFallbackInterface
(
contractABI
)
}
}
getReceiveInterface
(
contractABI
)
{
getReceiveInterface
(
contractABI
)
{
return
txHelper
.
getReceiveInterface
(
contractABI
)
return
getReceiveInterface
(
contractABI
)
}
}
getInputs
(
funABI
)
{
getInputs
(
funABI
)
{
if
(
!
funABI
.
inputs
)
{
if
(
!
funABI
.
inputs
)
{
return
''
return
''
}
}
return
txHelper
.
inputParametersDeclarationToString
(
funABI
.
inputs
)
return
inputParametersDeclarationToString
(
funABI
.
inputs
)
}
}
/**
/**
...
@@ -309,7 +318,7 @@ module.exports = class UniversalDApp {
...
@@ -309,7 +318,7 @@ module.exports = class UniversalDApp {
runTx
(
args
,
confirmationCb
,
continueCb
,
promptCb
,
cb
)
{
runTx
(
args
,
confirmationCb
,
continueCb
,
promptCb
,
cb
)
{
const
self
=
this
const
self
=
this
async
.
waterfall
([
waterfall
([
function
getGasLimit
(
next
)
{
function
getGasLimit
(
next
)
{
if
(
self
.
transactionContextAPI
.
getGasLimit
)
{
if
(
self
.
transactionContextAPI
.
getGasLimit
)
{
return
self
.
transactionContextAPI
.
getGasLimit
(
next
)
return
self
.
transactionContextAPI
.
getGasLimit
(
next
)
...
...
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