Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33_sdk
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
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
harrylee2015
chain33_sdk
Commits
9c8815d3
Commit
9c8815d3
authored
May 25, 2018
by
lihailei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix checked out bugs.
parent
3990abb9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
26 deletions
+28
-26
common.go
src/common/common.go
+18
-0
contract.go
src/controllers/contract.go
+10
-26
No files found.
src/common/common.go
View file @
9c8815d3
...
@@ -4,12 +4,15 @@ import (
...
@@ -4,12 +4,15 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"bytes"
log
"github.com/inconshreveable/log15"
log
"github.com/inconshreveable/log15"
"gitlab.33.cn/chain33/chain33/account"
"gitlab.33.cn/chain33/chain33/account"
common
"gitlab.33.cn/chain33/chain33/common"
common
"gitlab.33.cn/chain33/chain33/common"
crypto
"gitlab.33.cn/chain33/chain33/common/crypto"
crypto
"gitlab.33.cn/chain33/chain33/common/crypto"
jsonrpc
"gitlab.33.cn/chain33/chain33/rpc"
jsonrpc
"gitlab.33.cn/chain33/chain33/rpc"
"gitlab.33.cn/chain33/chain33/types"
"gitlab.33.cn/chain33/chain33/types"
"io/ioutil"
"net/http"
"os"
"os"
)
)
...
@@ -122,6 +125,21 @@ func (c *RpcCtx) RunWithoutMarshal() (string, error) {
...
@@ -122,6 +125,21 @@ func (c *RpcCtx) RunWithoutMarshal() (string, error) {
}
}
return
res
,
nil
return
res
,
nil
}
}
func
SendTransaction
(
tx
*
types
.
Transaction
)
(
string
,
error
)
{
poststr
:=
fmt
.
Sprintf
(
`{"jsonrpc":"2.0","id":2,"method":"Chain33.SendTransaction","params":[{"data":"%v"}]}`
,
common
.
ToHex
(
types
.
Encode
(
tx
)))
resp
,
err
:=
http
.
Post
(
GetJrpcURL
(),
"application/json"
,
bytes
.
NewBufferString
(
poststr
))
if
err
!=
nil
{
panic
(
err
)
}
defer
resp
.
Body
.
Close
()
b
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
panic
(
err
)
}
return
string
(
b
),
err
}
func
Getprivkey
(
key
string
)
crypto
.
PrivKey
{
func
Getprivkey
(
key
string
)
crypto
.
PrivKey
{
cr
,
err
:=
crypto
.
New
(
types
.
GetSignatureTypeName
(
types
.
SECP256K1
))
cr
,
err
:=
crypto
.
New
(
types
.
GetSignatureTypeName
(
types
.
SECP256K1
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
src/controllers/contract.go
View file @
9c8815d3
...
@@ -2,16 +2,14 @@ package controllers
...
@@ -2,16 +2,14 @@ package controllers
import
(
import
(
"github.com/astaxie/beego"
"github.com/astaxie/beego"
"gitlab.33.cn/chain33/chain33/account"
.
"gitlab.33.cn/chain33/chain33/common"
jsonrpc
"gitlab.33.cn/chain33/chain33/rpc"
jsonrpc
"gitlab.33.cn/chain33/chain33/rpc"
"gitlab.33.cn/chain33/chain33/types"
"gitlab.33.cn/chain33/chain33/types"
.
"gitlab.33.cn/lihailei/chain33_sdk/src/common"
.
"gitlab.33.cn/lihailei/chain33_sdk/src/common"
"encoding/json"
"encoding/json"
"fmt"
blacklist
"gitlab.33.cn/lihailei/chain33_sdk/src/models/contract/blacklist/types"
blacklist
"gitlab.33.cn/lihailei/chain33_sdk/src/models/contract/blacklist/types"
r
"math/rand"
"net/http"
"net/http"
)
)
...
@@ -35,11 +33,11 @@ func (c *ContractController) Invoke() {
...
@@ -35,11 +33,11 @@ func (c *ContractController) Invoke() {
if
c
.
Ctx
.
Request
.
Method
==
http
.
MethodPost
&&
funcName
==
blacklist
.
FuncName_CreateOrg
{
if
c
.
Ctx
.
Request
.
Method
==
http
.
MethodPost
&&
funcName
==
blacklist
.
FuncName_CreateOrg
{
var
org
blacklist
.
Org
var
org
blacklist
.
Org
json
.
Unmarshal
(
c
.
Ctx
.
Input
.
RequestBody
,
&
org
)
json
.
Unmarshal
(
c
.
Ctx
.
Input
.
RequestBody
,
&
org
)
fmt
.
Println
(
"orgName:"
,
org
.
OrgName
)
action
:=
&
blacklist
.
BlackAction
{
Value
:
&
blacklist
.
BlackAction_Or
{
&
org
},
FuncName
:
blacklist
.
FuncName_CreateOrg
}
action
:=
&
blacklist
.
BlackAction
{
Value
:
&
blacklist
.
BlackAction_Or
{
&
org
},
FuncName
:
blacklist
.
FuncName_CreateOrg
}
privKey
:=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
addr
,
priv
:=
Genaddress
()
res
,
err
:=
sendTx
(
"user.blacklist"
,
privKey
,
types
.
Encode
(
action
))
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"user.blacklist"
),
Payload
:
types
.
Encode
(
action
),
Fee
:
1e6
,
To
:
addr
}
fmt
.
Println
(
res
)
tx
.
Sign
(
types
.
SECP256K1
,
priv
)
res
,
err
:=
SendTransaction
(
tx
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
Data
[
"json"
]
=
err
.
Error
()
c
.
Data
[
"json"
]
=
err
.
Error
()
c
.
ServeJSON
()
c
.
ServeJSON
()
...
@@ -71,8 +69,10 @@ func (c *ContractController) Invoke() {
...
@@ -71,8 +69,10 @@ func (c *ContractController) Invoke() {
var
tr
blacklist
.
Transaction
var
tr
blacklist
.
Transaction
json
.
Unmarshal
(
c
.
Ctx
.
Input
.
RequestBody
,
&
tr
)
json
.
Unmarshal
(
c
.
Ctx
.
Input
.
RequestBody
,
&
tr
)
action
:=
&
blacklist
.
BlackAction
{
Value
:
&
blacklist
.
BlackAction_Tr
{
&
tr
},
FuncName
:
blacklist
.
FuncName_Transfer
}
action
:=
&
blacklist
.
BlackAction
{
Value
:
&
blacklist
.
BlackAction_Tr
{
&
tr
},
FuncName
:
blacklist
.
FuncName_Transfer
}
privKey
:=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
addr
,
priv
:=
Genaddress
()
res
,
err
:=
sendTx
(
"user.blacklist"
,
privKey
,
types
.
Encode
(
action
))
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"user.blacklist"
),
Payload
:
types
.
Encode
(
action
),
Fee
:
1e6
,
To
:
addr
}
tx
.
Sign
(
types
.
SECP256K1
,
priv
)
res
,
err
:=
SendTransaction
(
tx
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
Data
[
"json"
]
=
err
.
Error
()
c
.
Data
[
"json"
]
=
err
.
Error
()
c
.
ServeJSON
()
c
.
ServeJSON
()
...
@@ -83,22 +83,6 @@ func (c *ContractController) Invoke() {
...
@@ -83,22 +83,6 @@ func (c *ContractController) Invoke() {
}
}
}
}
func
sendTx
(
execer
string
,
privKey
string
,
body
[]
byte
)
(
string
,
error
)
{
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
execer
),
Payload
:
body
,
Fee
:
1e6
}
tx
.
Nonce
=
r
.
Int63
()
_
,
priv
:=
Genaddress
()
tx
.
Sign
(
types
.
SECP256K1
,
priv
)
tx
.
To
=
account
.
ExecAddress
(
execer
)
.
String
()
data
:=
ToHex
(
types
.
Encode
(
tx
))
params
:=
jsonrpc
.
RawParm
{
Data
:
data
,
}
ctx
:=
NewRpcCtx
(
GetJrpcURL
(),
"Chain33.SendTransaction"
,
params
,
nil
)
res
,
err
:=
ctx
.
RunWithoutMarshal
()
return
res
,
err
}
func
queryChain
(
req
jsonrpc
.
Query4Jrpc
)
([]
byte
,
error
)
{
func
queryChain
(
req
jsonrpc
.
Query4Jrpc
)
([]
byte
,
error
)
{
var
res
interface
{}
var
res
interface
{}
ctx
:=
NewRpcCtx
(
GetJrpcURL
(),
"Chain33.Query"
,
req
,
&
res
)
ctx
:=
NewRpcCtx
(
GetJrpcURL
(),
"Chain33.Query"
,
req
,
&
res
)
...
...
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