Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
6aa5072a
Commit
6aa5072a
authored
Jan 02, 2019
by
kingwang
Committed by
33cn
Jan 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add execname && execaddress
parent
e3630603
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
js.go
plugin/dapp/js/executor/js.go
+8
-0
runtime.go
plugin/dapp/js/executor/runtime.go
+65
-0
No files found.
plugin/dapp/js/executor/js.go
View file @
6aa5072a
...
...
@@ -24,6 +24,7 @@ func init() {
if
err
!=
nil
{
panic
(
err
)
}
execaddressFunc
(
basevm
)
}
//Init 插件初始化
...
...
@@ -170,6 +171,12 @@ func (u *js) getlocaldbFunc(vm *otto.Otto, name string) {
})
}
func
(
u
*
js
)
execnameFunc
(
vm
*
otto
.
Otto
,
name
string
)
{
vm
.
Set
(
"execname"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
return
okReturn
(
vm
,
name
)
})
}
func
(
u
*
js
)
listdbFunc
(
vm
*
otto
.
Otto
,
name
string
)
{
//List(prefix, key []byte, count, direction int32) ([][]byte, error)
_
,
plocal
:=
calcAllPrefix
(
name
)
...
...
@@ -221,6 +228,7 @@ func (u *js) createVM(name string, tx *types.Transaction, index int) (*otto.Otto
u
.
getstatedbFunc
(
vm
,
name
)
u
.
getlocaldbFunc
(
vm
,
name
)
u
.
listdbFunc
(
vm
,
name
)
u
.
execnameFunc
(
vm
,
name
)
return
vm
,
nil
}
...
...
plugin/dapp/js/executor/runtime.go
0 → 100644
View file @
6aa5072a
package
executor
import
(
"github.com/33cn/chain33/common/address"
"github.com/robertkrimen/otto"
)
//让 js 具有访问 区块链 的一些能力
func
execaddressFunc
(
vm
*
otto
.
Otto
)
{
vm
.
Set
(
"execaddress"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
key
,
err
:=
call
.
Argument
(
0
)
.
ToString
()
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
addr
:=
address
.
ExecAddress
(
key
)
return
okReturn
(
vm
,
addr
)
})
}
/*
//chain33 相关的账户操作函数 (操作某个execer 下面的 symbol)
function Account(execer, symbol) {
this.execer = execer
this.symbol = symbol
}
func Receipt(kvs, logs) {
this.kvs = kvs
this.logs = logs
}
var obj = new Account(execer, symbol)
//init 函数才能使用的两个函数(或者增发)
genesis_init(obj, addr string, amount int64)
genesis_exec_init(obj, execer, addr string, amount int64)
load_account(obj, addr) Account
get_balance(obj, addr, execer) Account
transfer(obj, from, to, amount) Receipt
transfer_to_exec(obj, execer, addr, amount) Receipt
withdraw(obj, execer, addr, amount) Receipt
exec_frozen(obj, addr) Receipt
exec_active(obj, addr) Receipt
exec_transfer(obj, from, to, amount) Receipt
exec_deposit(obj, addr, amount) Receipt
exec_withdraw(obj, addr, amount) Receipt
//table
//要开发一个适合json的table, row 就是一个 js object
//handle := new_table(config)
//table_add(handle, row)
//table_replace(handle, row)
//table_del(handle, row)
//table_savekvs(handle)
//table_close(handle)
//join table 的操作(接口完全相同)
//handle3 := new_table(newcofifg{config1, config2})
//获取系统随机数的接口
//randnum
//获取前一个区块hash的接口
//prev_blockhash()
*/
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