Commit e0e0e372 authored by linj's avatar linj

update chain33 20190109

parent cd952ee4
......@@ -20,6 +20,11 @@ chain33背后故事: [chain33诞生记](https://mp.weixin.qq.com/s/9g5ZFDKJi9uzR
视频教程: [视频教程](https://chain.33.cn/document/90)
# 感谢
[腾讯玄武实验室](https://github.com/33cn/chain33/issues?utf8=%E2%9C%93&q=label%3A%E8%85%BE%E8%AE%AF%E7%8E%84%E6%AD%A6%E5%AE%9E%E9%AA%8C%E5%AE%A4)
## Building from source
环境要求: Go (version 1.9 or later)
......
......@@ -276,8 +276,8 @@ func (acc *DB) loadAccountsHistory(api client.QueueProtocolAPI, addrs []string,
// GetBalance 获取某个状态下账户余额
func (acc *DB) GetBalance(api client.QueueProtocolAPI, in *types.ReqBalance) ([]*types.Account, error) {
switch in.GetExecer() {
case types.ExecName("coins"):
// load account
if in.AssetExec == in.Execer || "" == in.Execer {
addrs := in.GetAddresses()
var exaddrs []string
for _, addr := range addrs {
......@@ -306,34 +306,35 @@ func (acc *DB) GetBalance(api client.QueueProtocolAPI, in *types.ReqBalance) ([]
}
}
return accounts, nil
default:
execaddress := address.ExecAddress(in.GetExecer())
addrs := in.GetAddresses()
var accounts []*types.Account
for _, addr := range addrs {
var account *types.Account
var err error
if len(in.StateHash) == 0 {
account, err = acc.LoadExecAccountQueue(api, addr, execaddress)
if err != nil {
log.Error("GetBalance", "err", err.Error())
continue
}
} else {
hash, err := common.FromHex(in.StateHash)
if err != nil {
return nil, err
}
account, err = acc.LoadExecAccountHistoryQueue(api, addr, execaddress, hash)
if err != nil {
log.Error("GetBalance", "err", err.Error())
continue
}
}
// load exec account
execaddress := address.ExecAddress(in.GetExecer())
addrs := in.GetAddresses()
var accounts []*types.Account
for _, addr := range addrs {
var account *types.Account
var err error
if len(in.StateHash) == 0 {
account, err = acc.LoadExecAccountQueue(api, addr, execaddress)
if err != nil {
log.Error("GetBalance", "err", err.Error())
continue
}
} else {
hash, err := common.FromHex(in.StateHash)
if err != nil {
return nil, err
}
account, err = acc.LoadExecAccountHistoryQueue(api, addr, execaddress, hash)
if err != nil {
log.Error("GetBalance", "err", err.Error())
continue
}
accounts = append(accounts, account)
}
return accounts, nil
accounts = append(accounts, account)
}
return accounts, nil
}
// GetExecBalance 通过account模块获取地址账户在合约中的余额
......
......@@ -108,21 +108,24 @@ function start_chain33() {
echo "=========== #transfer to miner addr ============="
hash=$(${CLI} send coins transfer -a 10000 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
echo "${hash}"
sleep ${chain33BlockTime}
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
if [[ ${result} != '"ExecOk"' ]]; then
echo "Failed"
${CLI} tx query -s "${hash}" | jq '.' | cat
exit 1
fi
echo "=========== #transfer to token amdin ============="
hash=$(${CLI} send coins transfer -a 10 -n test -t 1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
echo "${hash}"
sleep ${chain33BlockTime}
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
if [[ ${result} != '"ExecOk"' ]]; then
echo "Failed"
${CLI} tx query -s "${hash}" | jq '.' | cat
exit 1
fi
......@@ -131,10 +134,12 @@ function start_chain33() {
signData=$(${CLI} wallet sign -d "${rawData}" -k 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc)
hash=$(${CLI} wallet send -d "${signData}")
echo "${hash}"
sleep ${chain33BlockTime}
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
if [[ ${result} != '"ExecOk"' ]]; then
echo "Failed"
${CLI} tx query -s "${hash}" | jq '.' | cat
exit 1
fi
......
......@@ -121,21 +121,24 @@ function start_chain33() {
echo "=========== #transfer to miner addr ============="
hash=$(${CLI} send coins transfer -a 10000 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
echo "${hash}"
sleep ${chain33BlockTime}
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
if [[ ${result} != '"ExecOk"' ]]; then
echo "Failed"
${CLI} tx query -s "${hash}" | jq '.' | cat
exit 1
fi
echo "=========== #transfer to token amdin ============="
hash=$(${CLI} send coins transfer -a 10 -n test -t 1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
echo "${hash}"
sleep ${chain33BlockTime}
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
if [[ ${result} != '"ExecOk"' ]]; then
echo "Failed"
${CLI} tx query -s "${hash}" | jq '.' | cat
exit 1
fi
......@@ -144,10 +147,12 @@ function start_chain33() {
signData=$(${CLI} wallet sign -d "${rawData}" -k 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc)
hash=$(${CLI} wallet send -d "${signData}")
echo "${hash}"
sleep ${chain33BlockTime}
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
result=$(${CLI} tx query -s "${hash}" | jq '.receipt.tyName')
if [[ ${result} != '"ExecOk"' ]]; then
echo "Failed"
${CLI} tx query -s "${hash}" | jq '.' | cat
exit 1
fi
......
......@@ -312,16 +312,6 @@ func (table *Table) getPrimaryFromData(data types.Message) (primaryKey []byte, e
return
}
//ListIndex list table index
func (table *Table) ListIndex(indexName string, prefix []byte, primaryKey []byte, count, direction int32) (rows []*Row, err error) {
kvdb, ok := table.kvdb.(db.KVDB)
if !ok {
return nil, errors.New("list only support KVDB interface")
}
query := &Query{table: table, kvdb: kvdb}
return query.ListIndex(indexName, prefix, primaryKey, count, direction)
}
//Replace 如果有重复的,那么替换
func (table *Table) Replace(data types.Message) error {
if err := table.checkIndex(data); err != nil {
......@@ -612,15 +602,8 @@ func (table *Table) getModify(row, oldrow *Row, index string) ([]byte, []byte, b
return indexkey, oldkey, true, nil
}
//GetQuery 获取查询结构(允许传入 kvdb 为nil)
//GetQuery 获取查询结构
func (table *Table) GetQuery(kvdb db.KVDB) *Query {
if kvdb == nil {
var ok bool
kvdb, ok = table.kvdb.(db.KVDB)
if !ok {
return nil
}
}
return &Query{table: table, kvdb: kvdb}
}
......@@ -628,11 +611,6 @@ func (table *Table) getMeta() RowMeta {
return table.meta
}
//GetMeta 获取meta
func (table *Table) GetMeta() RowMeta {
return table.getMeta()
}
func (table *Table) getOpt() *Option {
return table.opt
}
......@@ -206,7 +206,20 @@ func (c *channelClient) GetAddrOverview(parm *types.ReqAddr) (*types.AddrOvervie
// GetBalance get balance
func (c *channelClient) GetBalance(in *types.ReqBalance) ([]*types.Account, error) {
return c.accountdb.GetBalance(c.QueueProtocolAPI, in)
// in.AssetExec & in.AssetSymbol 新增参数,
// 不填时兼容原来的调用
if in.AssetExec == "" || in.AssetSymbol == "" {
in.AssetSymbol = "bty"
in.AssetExec = "coins"
return c.accountdb.GetBalance(c.QueueProtocolAPI, in)
}
acc, err := account.NewAccountDB(in.AssetExec, in.AssetSymbol, nil)
if err != nil {
log.Error("GetBalance", "Error", err.Error())
return nil, err
}
return acc.GetBalance(c.QueueProtocolAPI, in)
}
// GetAllExecBalance get balance of exec
......@@ -288,3 +301,49 @@ func (c *channelClient) GetExecBalance(in *types.ReqGetExecBalance) (*types.Repl
}
return resp, nil
}
// GetAssetBalance 通用的获得资产的接口
func (c *channelClient) GetAssetBalance(in *types.ReqBalance) ([]*types.Account, error) {
if in.AssetSymbol == "" || in.AssetExec == "" {
return nil, types.ErrInvalidParam
}
acc, err := account.NewAccountDB(in.AssetExec, in.AssetSymbol, nil)
if err != nil {
return nil, err
}
// load balance
if in.AssetExec == in.Execer || in.Execer == "" {
addrs := in.GetAddresses()
var queryAddrs []string
for _, addr := range addrs {
if err := address.CheckAddress(addr); err != nil {
addr = string(acc.AccountKey(addr))
}
queryAddrs = append(queryAddrs, addr)
}
accounts, err := acc.LoadAccounts(c.QueueProtocolAPI, queryAddrs)
if err != nil {
log.Error("GetAssetBalance", "err", err.Error(), "exec", in.AssetExec, "symbol", in.AssetSymbol,
"address", queryAddrs)
return nil, err
}
return accounts, nil
}
// load exec balance
execaddress := address.ExecAddress(in.GetExecer())
addrs := in.GetAddresses()
var accounts []*types.Account
for _, addr := range addrs {
acc, err := acc.LoadExecAccountQueue(c.QueueProtocolAPI, addr, execaddress)
if err != nil {
log.Error("GetAssetBalance for exector", "err", err.Error(), "exec", in.AssetExec,
"symbol", in.AssetSymbol, "address", addr, "where", in.Execer)
continue
}
accounts = append(accounts, acc)
}
return accounts, nil
}
......@@ -361,3 +361,66 @@ func TestChannelClient_GetBalance(t *testing.T) {
// assert.NotNil(t, data)
// assert.Nil(t, err)
// }
func testChannelClient_GetAssetBalanceCoin(t *testing.T) {
api := new(mocks.QueueProtocolAPI)
db := new(account.DB)
client := &channelClient{
QueueProtocolAPI: api,
accountdb: db,
}
head := &types.Header{StateHash: []byte("sdfadasds")}
api.On("GetLastHeader").Return(head, nil)
var acc = &types.Account{Addr: "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt", Balance: 100}
accv := types.Encode(acc)
storevalue := &types.StoreReplyValue{}
storevalue.Values = append(storevalue.Values, accv)
api.On("StoreGet", mock.Anything).Return(storevalue, nil)
var addrs = []string{"1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt"}
var in = &types.ReqBalance{
AssetSymbol: "bty",
AssetExec: "coins",
Execer: "coins",
Addresses: addrs,
}
data, err := client.GetAssetBalance(in)
assert.Nil(t, err)
assert.Equal(t, acc.Addr, data[0].Addr)
}
func testChannelClient_GetAssetBalanceOther(t *testing.T) {
api := new(mocks.QueueProtocolAPI)
db := new(account.DB)
client := &channelClient{
QueueProtocolAPI: api,
accountdb: db,
}
head := &types.Header{StateHash: []byte("sdfadasds")}
api.On("GetLastHeader").Return(head, nil)
var acc = &types.Account{Addr: "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt", Balance: 100}
accv := types.Encode(acc)
storevalue := &types.StoreReplyValue{}
storevalue.Values = append(storevalue.Values, accv)
api.On("StoreGet", mock.Anything).Return(storevalue, nil)
var addrs = []string{"1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt"}
var in = &types.ReqBalance{
AssetSymbol: "bty",
AssetExec: "coins",
Execer: types.ExecName("ticket"),
Addresses: addrs,
}
data, err := client.GetAssetBalance(in)
assert.Nil(t, err)
assert.Equal(t, acc.Addr, data[0].Addr)
}
func TestChannelClient_GetAssetBalance(t *testing.T) {
testChannelClient_GetAssetBalanceCoin(t)
testChannelClient_GetAssetBalanceOther(t)
}
......@@ -741,19 +741,12 @@ func (c *Chain33) GetWalletStatus(in types.ReqNil, result *interface{}) error {
// GetBalance get balance
func (c *Chain33) GetBalance(in types.ReqBalance, result *interface{}) error {
balances, err := c.cli.GetBalance(&in)
if err != nil {
return err
}
var accounts []*rpctypes.Account
for _, balance := range balances {
accounts = append(accounts, &rpctypes.Account{Addr: balance.GetAddr(),
Balance: balance.GetBalance(),
Currency: balance.GetCurrency(),
Frozen: balance.GetFrozen()})
}
*result = accounts
*result = fmtAccount(balances)
return nil
}
......@@ -1209,3 +1202,14 @@ func convertBlockDetails(details []*types.BlockDetail, retDetails *rpctypes.Bloc
}
return nil
}
func fmtAccount(balances []*types.Account) []*rpctypes.Account {
var accounts []*rpctypes.Account
for _, balance := range balances {
accounts = append(accounts, &rpctypes.Account{Addr: balance.GetAddr(),
Balance: balance.GetBalance(),
Currency: balance.GetCurrency(),
Frozen: balance.GetFrozen()})
}
return accounts
}
......@@ -10,6 +10,7 @@ import (
"encoding/hex"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/common"
rpctypes "github.com/33cn/chain33/rpc/types"
......@@ -373,6 +374,7 @@ func newTestChain33(api *mocks.QueueProtocolAPI) *Chain33 {
return &Chain33{
cli: channelClient{
QueueProtocolAPI: api,
accountdb: account.NewCoinsAccount(),
},
}
}
......@@ -1290,3 +1292,58 @@ func TestChain33_GetExecBalance(t *testing.T) {
err = client.GetExecBalance(in, &testResult2)
assert.NotNil(t, err)
}
func TestChain33_GetBalance(t *testing.T) {
api := new(mocks.QueueProtocolAPI)
client := newTestChain33(api)
var addrs = []string{"1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt"}
cases := []struct {
In types.ReqBalance
}{
{In: types.ReqBalance{
Execer: types.ExecName("coins"),
Addresses: addrs,
}},
{In: types.ReqBalance{
Execer: types.ExecName("ticket"),
Addresses: addrs,
}},
{In: types.ReqBalance{
AssetSymbol: "bty",
AssetExec: "coins",
Execer: types.ExecName("ticket"),
Addresses: addrs,
}},
{In: types.ReqBalance{
AssetSymbol: "bty",
AssetExec: "coins",
Execer: types.ExecName("coins"),
Addresses: addrs,
}},
}
for _, c := range cases {
c := c
t.Run("test GetBalance", func(t *testing.T) {
head := &types.Header{StateHash: []byte("sdfadasds")}
api.On("GetLastHeader").Return(head, nil)
var acc = &types.Account{Addr: "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt", Balance: 100}
accv := types.Encode(acc)
storevalue := &types.StoreReplyValue{}
storevalue.Values = append(storevalue.Values, accv)
api.On("StoreGet", mock.Anything).Return(storevalue, nil)
var data interface{}
err := client.GetBalance(c.In, &data)
assert.Nil(t, err)
result := data.([]*rpctypes.Account)
assert.Equal(t, 1, len(result))
//t.Error("result", "x", result)
assert.Equal(t, acc.Addr, result[0].Addr)
assert.Equal(t, int64(100), result[0].Balance)
})
}
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package commands
import (
"encoding/json"
"fmt"
"math"
"os"
"strings"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/rpc/jsonclient"
rpcTypes "github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/spf13/cobra"
)
// AssetCmd command
func AssetCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "asset",
Short: "Asset query",
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(
GetAssetBalanceCmd(),
)
return cmd
}
// GetAssetBalanceCmd query asset balance
func GetAssetBalanceCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "balance",
Short: "Query asset balance",
Run: assetBalance,
}
addAssetBalanceFlags(cmd)
return cmd
}
func addAssetBalanceFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addr", "a", "", "account addr")
cmd.MarkFlagRequired("addr")
cmd.Flags().StringP("exec", "e", "", getExecuterNameString())
cmd.Flags().StringP("asset_exec", "", "coins", "the asset executor")
cmd.MarkFlagRequired("asset_exec")
cmd.Flags().StringP("asset_symbol", "", "bty", "the asset symbol")
cmd.MarkFlagRequired("asset_symbol")
cmd.Flags().IntP("height", "", -1, "block height")
}
func assetBalance(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
addr, _ := cmd.Flags().GetString("addr")
execer, _ := cmd.Flags().GetString("exec")
asset_symbol, _ := cmd.Flags().GetString("asset_symbol")
asset_exec, _ := cmd.Flags().GetString("asset_exec")
height, _ := cmd.Flags().GetInt("height")
err := address.CheckAddress(addr)
if err != nil {
if err = address.CheckMultiSignAddress(addr); err != nil {
fmt.Fprintln(os.Stderr, types.ErrInvalidAddress)
return
}
}
if execer == "" {
execer = asset_exec
}
if ok := types.IsAllowExecName([]byte(execer), []byte(execer)); !ok {
fmt.Fprintln(os.Stderr, types.ErrExecNameNotAllow)
return
}
stateHash := ""
if height >= 0 {
params := types.ReqBlocks{
Start: int64(height),
End: int64(height),
IsDetail: false,
}
var res rpcTypes.Headers
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.GetHeaders", params, &res)
_, err := ctx.RunResult()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
h := res.Items[0]
stateHash = h.StateHash
}
var addrs []string
addrs = append(addrs, addr)
params := types.ReqBalance{
Addresses: addrs,
Execer: execer,
StateHash: stateHash,
AssetExec: asset_exec,
AssetSymbol: asset_symbol,
}
var res []*rpcTypes.Account
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.GetBalance", params, &res)
ctx.SetResultCb(parseGetBalanceRes)
ctx.Run()
}
// CreateAssetSendToExec 通用的创建 send_exec 交易, 额外指定资产合约
func CreateAssetSendToExec(cmd *cobra.Command, args []string, fromExec string) {
paraName, _ := cmd.Flags().GetString("paraName")
exec, _ := cmd.Flags().GetString("exec")
exec = getRealExecName(paraName, exec)
to, err := GetExecAddr(exec)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
amount, _ := cmd.Flags().GetFloat64("amount")
note, _ := cmd.Flags().GetString("note")
symbol, _ := cmd.Flags().GetString("symbol")
payload := &types.AssetsTransferToExec{
To: to,
Amount: int64(math.Trunc((amount+0.0000001)*1e4)) * 1e4,
Note: []byte(note),
Cointoken: symbol,
ExecName: exec,
}
data, err := json.Marshal(&payload)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
params := &rpcTypes.CreateTxIn{
Execer: types.ExecName(fromExec),
ActionName: "TransferToExec",
Payload: data,
}
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
ctx.RunWithoutMarshal()
}
// CreateAssetWithdraw 通用的创建 withdraw 交易, 额外指定资产合约
func CreateAssetWithdraw(cmd *cobra.Command, args []string, fromExec string) {
exec, _ := cmd.Flags().GetString("exec")
paraName, _ := cmd.Flags().GetString("paraName")
exec = getRealExecName(paraName, exec)
amount, _ := cmd.Flags().GetFloat64("amount")
note, _ := cmd.Flags().GetString("note")
symbol, _ := cmd.Flags().GetString("symbol")
exec = getRealExecName(paraName, exec)
execAddr, err := GetExecAddr(exec)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
payload := &types.AssetsWithdraw{
To: execAddr,
Amount: int64(math.Trunc((amount+0.0000001)*1e4)) * 1e4,
Note: []byte(note),
Cointoken: symbol,
ExecName: exec,
}
data, err := json.Marshal(&payload)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
params := &rpcTypes.CreateTxIn{
Execer: types.ExecName(fromExec),
ActionName: "Withdraw",
Payload: data,
}
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
ctx.RunWithoutMarshal()
}
// CreateAssetTransfer 通用的创建 transfer 交易, 额外指定资产合约
func CreateAssetTransfer(cmd *cobra.Command, args []string, fromExec string) {
toAddr, _ := cmd.Flags().GetString("to")
amount, _ := cmd.Flags().GetFloat64("amount")
note, _ := cmd.Flags().GetString("note")
symbol, _ := cmd.Flags().GetString("symbol")
payload := &types.AssetsTransfer{
To: toAddr,
Amount: int64(math.Trunc((amount+0.0000001)*1e4)) * 1e4,
Note: []byte(note),
Cointoken: symbol,
}
data, err := json.Marshal(&payload)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
params := &rpcTypes.CreateTxIn{
Execer: types.ExecName(fromExec),
ActionName: "Transfer",
Payload: data,
}
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
ctx.RunWithoutMarshal()
}
// GetExecAddr 获取执行器地址
func GetExecAddr(exec string) (string, error) {
if ok := types.IsAllowExecName([]byte(exec), []byte(exec)); !ok {
return "", types.ErrExecNameNotAllow
}
addrResult := address.ExecAddress(exec)
result := addrResult
return result, nil
}
func getRealExecName(paraName string, name string) string {
if strings.HasPrefix(name, "user.p.") {
return name
}
return paraName + name
}
......@@ -205,6 +205,8 @@ type ReqBalance struct {
//执行器名称
Execer string `protobuf:"bytes,2,opt,name=execer,proto3" json:"execer,omitempty"`
StateHash string `protobuf:"bytes,3,opt,name=stateHash,proto3" json:"stateHash,omitempty"`
AssetExec string `protobuf:"bytes,4,opt,name=asset_exec,json=assetExec,proto3" json:"asset_exec,omitempty"`
AssetSymbol string `protobuf:"bytes,5,opt,name=asset_symbol,json=assetSymbol,proto3" json:"asset_symbol,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
......@@ -256,6 +258,20 @@ func (m *ReqBalance) GetStateHash() string {
return ""
}
func (m *ReqBalance) GetAssetExec() string {
if m != nil {
return m.AssetExec
}
return ""
}
func (m *ReqBalance) GetAssetSymbol() string {
if m != nil {
return m.AssetSymbol
}
return ""
}
// Account 的列表
type Accounts struct {
Acc []*Account `protobuf:"bytes,1,rep,name=acc,proto3" json:"acc,omitempty"`
......@@ -403,28 +419,30 @@ func init() {
func init() { proto.RegisterFile("account.proto", fileDescriptor_8e28828dcb8d24f0) }
var fileDescriptor_8e28828dcb8d24f0 = []byte{
// 360 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x41, 0x4f, 0x32, 0x31,
0x10, 0x4d, 0x59, 0x60, 0xd9, 0x21, 0x1f, 0x87, 0x1e, 0xc8, 0x86, 0x7c, 0xc6, 0xcd, 0x9e, 0xf6,
0x60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0x7c, 0x9d, 0xfa, 0x55, 0xfd, 0x87, 0xc8, 0xae,
0x01, 0xb5, 0x46, 0x1d, 0x93, 0x24, 0xc8, 0x22, 0x76, 0x2c, 0xd8, 0x45, 0xda, 0x69, 0x51, 0x39,
0xd1, 0x88, 0x79, 0x64, 0xbb, 0xb4, 0xe1, 0x06, 0xef, 0xb8, 0x5e, 0xb9, 0xb9, 0x22, 0x76, 0x2c,
0xa4, 0x57, 0xd0, 0xf3, 0xae, 0x9a, 0x26, 0x10, 0x70, 0x21, 0x9c, 0xf2, 0x79, 0x26, 0x4b, 0xa5,
0xf7, 0xd0, 0x6f, 0x2c, 0xbe, 0x61, 0x49, 0x4e, 0x2c, 0x33, 0x08, 0xfd, 0x67, 0xf9, 0x69, 0x40,
0x4f, 0xa7, 0x33, 0x18, 0x4c, 0x36, 0x1b, 0xab, 0x59, 0x0f, 0x59, 0xbf, 0x3b, 0x39, 0xbe, 0x3b,
0xbd, 0x39, 0xb1, 0x8d, 0x5b, 0x2e, 0x20, 0xf5, 0x9a, 0x0d, 0x86, 0x35, 0xaf, 0x4d, 0x2f, 0x67,
0x17, 0x4f, 0x6b, 0xb3, 0xda, 0xce, 0x73, 0x51, 0xbe, 0x8c, 0x8b, 0x42, 0xc8, 0xb1, 0x58, 0xf1,
0xb5, 0x2c, 0x8a, 0xb1, 0xeb, 0x9c, 0x77, 0xdd, 0x4f, 0x2e, 0xbe, 0x02, 0x00, 0x00, 0xff, 0xff,
0x7b, 0xae, 0x1c, 0x1e, 0xda, 0x02, 0x00, 0x00,
// 399 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xc1, 0x8e, 0xd3, 0x30,
0x10, 0x95, 0x9b, 0x76, 0xb3, 0x99, 0xc2, 0x1e, 0x7c, 0x58, 0x59, 0x2b, 0x56, 0x84, 0x9c, 0x72,
0x40, 0xa9, 0x44, 0xf8, 0x81, 0x56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90, 0xf8, 0x6d,
0x11, 0xb2, 0x7a, 0x01, 0x89, 0xcf, 0x01, 0xad, 0x45, 0x2b, 0x58, 0x1a, 0xe5, 0x89, 0x3c, 0x03,
0x3e, 0x49, 0xff, 0x5c, 0x34, 0xb4, 0x35, 0x91, 0xa1, 0xf2, 0x53, 0xd6, 0x29, 0x87, 0xef, 0x95,
0xdd, 0xd0, 0xc3, 0x12, 0x79, 0x06, 0xf8, 0x23, 0x80, 0xb2, 0x16, 0xdd, 0x67, 0xdf, 0x1d, 0xd2,
0x4e, 0x08, 0xf1, 0x11, 0xf3, 0x57, 0xf0, 0xec, 0x48, 0xdb, 0xc3, 0xae, 0x6a, 0x6b, 0x31, 0xa1,
0x86, 0x29, 0x61, 0x1f, 0x09, 0xca, 0x5e, 0xc3, 0x6d, 0x30, 0x6e, 0x79, 0x0a, 0x91, 0xd2, 0x9a,
0xbc, 0x5d, 0x3f, 0xcb, 0x53, 0xd9, 0x07, 0x98, 0x0e, 0xfe, 0xbb, 0x81, 0x69, 0x76, 0x61, 0x3a,
0x87, 0x38, 0xdc, 0xdb, 0xbf, 0x32, 0x0a, 0x74, 0xb6, 0x84, 0xbb, 0x79, 0x5d, 0xfb, 0x9d, 0x7d,
0x4c, 0xfd, 0xe9, 0xb0, 0xf3, 0xe9, 0xf0, 0xb7, 0x17, 0xb2, 0x62, 0x44, 0x06, 0x79, 0xd8, 0x39,
0x60, 0xe4, 0xb0, 0x6d, 0xf1, 0x72, 0xf9, 0xf8, 0x65, 0xeb, 0x36, 0xfb, 0xaa, 0xd0, 0xed, 0x6e,
0x56, 0x96, 0xba, 0x99, 0xe9, 0x8d, 0xda, 0x36, 0x65, 0x39, 0xa3, 0xc9, 0xea, 0x86, 0x3e, 0x86,
0xf2, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x61, 0x7c, 0x60, 0x1d, 0x03, 0x00, 0x00,
}
......@@ -38,8 +38,10 @@ message ReqBalance {
//地址列表
repeated string addresses = 1;
//执行器名称
string execer = 2;
string stateHash = 3;
string execer = 2;
string stateHash = 3;
string asset_exec = 4;
string asset_symbol = 5;
}
// Account 的列表
......
......@@ -60,6 +60,7 @@ func init() {
commands.VersionCmd(),
sendCmd,
closeCmd,
commands.AssetCmd(),
)
}
......
......@@ -205,27 +205,6 @@ func (mock *Chain33Mock) SendAndSign(priv crypto.PrivKey, hextx string) ([]byte,
return reply.GetMsg(), nil
}
//SendAndSignNonce 用外部传入的nonce 重写nonce
func (mock *Chain33Mock) SendAndSignNonce(priv crypto.PrivKey, hextx string, nonce int64) ([]byte, error) {
txbytes, err := hex.DecodeString(hextx)
if err != nil {
return nil, err
}
tx := &types.Transaction{}
err = types.Decode(txbytes, tx)
if err != nil {
return nil, err
}
tx.Nonce = nonce
tx.Fee = 1e6
tx.Sign(types.SECP256K1, priv)
reply, err := mock.api.SendTx(tx)
if err != nil {
return nil, err
}
return reply.GetMsg(), nil
}
func newWalletRealize(qAPI client.QueueProtocolAPI) {
seed := &types.SaveSeedByPw{
Seed: "subject hamster apple parent vital can adult chapter fork business humor pen tiger void elephant",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment