Skip to content

Commit

Permalink
Merge branch 'v0.3-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gordon-sero committed Nov 15, 2018
2 parents ad946fb + d3b181c commit 9cbc8c1
Show file tree
Hide file tree
Showing 56 changed files with 2,652 additions and 1,815 deletions.
4 changes: 4 additions & 0 deletions accounts/abi/abihelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"

"github.com/sero-cash/go-sero/common/hexutil"

"github.com/pkg/errors"

"github.com/sero-cash/go-czero-import/keys"
Expand Down Expand Up @@ -251,6 +253,8 @@ func (abi ABI) Transfer(input []byte, output []byte, state *state.StateDB, contr
}

sigdata := input[:4]
resstr, _ := hexutil.Bytes(sigdata[:]).MarshalText()
fmt.Printf("method hex = %s", resstr)
method, err := abi.MethodById(sigdata)
if err != nil {
return output, nil
Expand Down
65 changes: 65 additions & 0 deletions accounts/abi/abihelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
"testing"

"github.com/sero-cash/go-sero/common/hexutil"

"github.com/sero-cash/go-czero-import/keys"
"github.com/sero-cash/go-sero/common"
)
Expand Down Expand Up @@ -195,3 +197,66 @@ func TestABI_PrefixPack(t *testing.T) {
}

}

func verify(t *testing.T, jsondata, calldata string, exp string) {

abispec, err := JSON(strings.NewReader(jsondata))
if err != nil {
t.Fatal(err)
}

for _, m := range abispec.Methods {
x, _ := hexutil.Bytes(m.Id()).MarshalText()
fmt.Printf("\n %s", x)
}

cd := common.Hex2Bytes(calldata)
sigdata, argdata := cd[:4], cd[4:]
method, err := abispec.MethodById(sigdata)

if err != nil {
t.Fatal(err)
}

//data, err := method.Outputs.UnpackValues(argdata)
outd, err := method.Outputs.TranserApiValues(argdata, nil, common.Address{}, nil)

data, _ := hexutil.Bytes(outd[:]).MarshalText()
if string(data) != exp {
t.Fatalf("Mismatched length, \nexpected %s, \ngot %s", exp, string(data))
}

}
func TestNewUnpacker(t *testing.T) {
type unpackTest struct {
jsondata string
calldata string
exp string
}
testcases := []unpackTest{

{ // https://solidity.readthedocs.io/en/develop/abi-spec.html#use-of-dynamic-types
`[{"type":"function","name":"f", "outputs":[{"type":"uint256"},{"type":"uint32[]"},{"type":"bytes10"},{"type":"bytes"}]}]`,
// 0x123, [0x456, 0x789], "1234567890", "Hello, world!"
"26121ff0" + "00000000000000000000000000000000000000000000000000000000000001230000000000000000000000000000000000000000000000000000000000000080313233343536373839300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000",
"00000000000000000000000000000000000000000000000000000000000001230000000000000000000000000000000000000000000000000000000000000080313233343536373839300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000",
}, { // https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#examples
`[{"type":"function","name":"sam","outputs":[{"type":"bytes"},{"type":"bool"},{"type":"uint256[]"}]}]`,
// "dave", true and [1,2,3]
"7edba6c80000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000464617665000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003",
"a5643bf20000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000464617665000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003",
}, {
`[{"type":"function","name":"send","outputs":[{"type":"uint256"}]}]`,
"b46300ec0000000000000000000000000000000000000000000000000000000000000012",
"0000000000000000000000000000000000000000000000000000000000000012",
}, {
`[{"type":"function","name":"compareAndApprove","outputs":[{"type":"address"},{"type":"uint256"},{"type":"uint256"}]}]`,
"ce79fdce00000000000000000000000000000133700000deadbeef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"00000000000000000000000000000133700000deadbeef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
},
}
for _, c := range testcases {
verify(t, c.jsondata, c.calldata, c.exp)
}

}
3 changes: 3 additions & 0 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"sync"
"time"

"github.com/sero-cash/go-sero/zero/txs/assets"

"github.com/sero-cash/go-sero"
"github.com/sero-cash/go-sero/common"
"github.com/sero-cash/go-sero/common/math"
Expand Down Expand Up @@ -389,6 +391,7 @@ func (m callmsg) Data() []byte { return m.CallMsg.Data }
func (m callmsg) Currency() string {
return "sero"
}
func (m callmsg) Asset() assets.Asset { return assets.Asset{} }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
Expand Down
83 changes: 52 additions & 31 deletions accounts/keystore/keystore_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package keystore

import (
"github.com/sero-cash/go-czero-import/keys"
sero "github.com/sero-cash/go-sero"
"github.com/sero-cash/go-sero"
"github.com/sero-cash/go-sero/accounts"
"github.com/sero-cash/go-sero/common"
"github.com/sero-cash/go-sero/common/hexutil"
Expand All @@ -28,8 +28,8 @@ import (
"github.com/sero-cash/go-sero/log"
"github.com/sero-cash/go-sero/rlp"
"github.com/sero-cash/go-sero/zero/txs"
"github.com/sero-cash/go-sero/zero/txs/assets"
"github.com/sero-cash/go-sero/zero/txs/tx"
"github.com/sero-cash/go-sero/zero/utils"
)

// keystoreWallet implements the accounts.Wallet interface for the original
Expand Down Expand Up @@ -112,55 +112,76 @@ func (w *keystoreWallet) EncryptTx(account accounts.Account, tx *types.Transacti
func (w *keystoreWallet) EncryptTxWithSeed(seed common.Seed, btx *types.Transaction, txt *tx.T, state *state.StateDB) (*types.Transaction, error) {
w.keystore.mu.Lock()
defer w.keystore.mu.Unlock()
for i, ctx := range txt.CTxs {
tk := keys.Seed2Tk(seed.SeedToUint256())
outs, amount, err := txs.GetRoots(&tk, state.GetZState(), ctx.Cost().ToRef(), &ctx.Currency)
if err != nil {
return nil, err
ins := []tx.In{}
costTkn := txt.TokenCost()
costTkt := txt.TikectCost()
tk := keys.Seed2Tk(seed.SeedToUint256())
outs, tknMap, tktMap, err := txs.GetRoots(&tk, costTkn, costTkt)
if err != nil {
return nil, err
}
for _, out := range outs {
ins = append(ins, tx.In{Root: out})
}
for cy, value := range tknMap {
token := &assets.Token{
Currency: cy,
Value: value,
}
ins := []tx.In{}
for _, out := range outs {
ins = append(ins, tx.In{Root: out})
asset := assets.Asset{
Tkn: token,
}
txt.CTxs[i].Ins = ins

balance := amount
balance.SubU(ctx.Cost().ToRef())

if balance.Cmp(&utils.U256_0) > 0 {
selfOut := tx.Out{
Addr: keys.Seed2Addr(seed.SeedToUint256()),
Asset: asset,
Z: tx.TYPE_Z,
}
txt.Outs = append(txt.Outs, selfOut)
}
for catg, value := range tktMap {
for _, v := range value {
ticket := &assets.Ticket{
Category: catg,
Value: v,
}
asset := assets.Asset{
Tkt: ticket,
}
selfOut := tx.Out{
Addr: keys.Seed2Addr(seed.SeedToUint256()),
Value: balance,
Asset: asset,
Z: tx.TYPE_Z,
}
txt.CTxs[i].Outs = append(txt.CTxs[i].Outs, selfOut)
txt.Outs = append(txt.Outs, selfOut)
}

}

txt.Ins = ins

Ehash := rlpHash([]interface{}{
btx.GasPrice(),
btx.Data(),
btx.Currency(),
})
copy(txt.Ehash[:], Ehash[:])

log.Info("EncryptTxWithSeed : ", "ctx_num", len(txt.CTxs))
for _, ctx := range txt.CTxs {
for i, in := range ctx.Ins {
log.Info(" ctx_in : ", "index", i, "root", in.Root)
}
for i, out := range ctx.Outs {
log.Info(" ctx_out : ", "index", i, "to", hexutil.Encode(out.Addr[:]))
}
log.Info("EncryptTxWithSeed : ", "in_num", len(txt.Ins), "out_num", len(txt.Outs))

for i, in := range txt.Ins {
log.Info(" ctx_in : ", "index", i, "root", in.Root)
}
for i, out := range txt.Outs {
log.Info(" ctx_out : ", "index", i, "to", hexutil.Encode(out.Addr[:]))
}

stx, err := txs.Gen(seed.SeedToUint256(), txt, state.GetZState())
stx, err := txs.Gen(seed.SeedToUint256(), txt)
if err != nil {
return nil, err
}

for i, desc_z := range stx.Desc_Zs {
log.Info(" desc_z : ", "index", i, "nil", hexutil.Encode(desc_z.In.Nil[:]), "trace", hexutil.Encode(desc_z.In.Trace[:]))
for i, in := range stx.Desc_Z.Ins {
log.Info(" desc_z : ", "index", i, "nil", hexutil.Encode(in.Nil[:]), "trace", hexutil.Encode(in.Trace[:]))
}

return btx.WithEncrypt(&stx)
Expand Down Expand Up @@ -196,6 +217,6 @@ func (w *keystoreWallet) EncryptTxWithPassphrase(account accounts.Account, passp

func (w *keystoreWallet) IsMine(onceAddress common.Address) bool {
tk := w.account.Tk.ToUint512()
return keys.IsMyPKr(tk, onceAddress.ToUint512())

succ, _ := keys.IsMyPKr(tk, onceAddress.ToUint512())
return succ
}
6 changes: 6 additions & 0 deletions build/package/attach.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
PACKAGEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PACKAGEDIR}/czero/lib/
DATADIR="${PACKAGEDIR}/../datadir"
${PACKAGEDIR}/bin/gero --datadir=${DATADIR} attach

25 changes: 16 additions & 9 deletions build/package/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ LOCAL_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
echo $LOCAL_PATH
GERO_BASE=${LOCAL_PATH}/../../
#CZERO_PATH=${LOCAL_PATH}/../../../czero
#if [ ! -d ${CZERO_PATH} ]; then
# echo "the path ${CZERO_PATH} should be available for build czero"
# echo "please cd ${CZERO_PATH}\n git clone https://gitee.com/hyperspace/czero.git"
# exit
#compileCZero() {
# if [ ! -d ${CZERO_PATH} ]; then
# echo "the path ${CZERO_PATH} should be available for build czero"
# echo "please cd ${CZERO_PATH}\n git clone https://gitee.com/hyperspace/czero.git"
# exit
# fi
# cd ${CZERO_PATH}/build
# ./depends.sh
# cmake ..
# make clean
# make czero
#}
#if [ -z "$1" ]; then
# echo "No argument supplied"
#elif [ "x$1" == "xcompile" ]; then
# compileCZero
#fi
#cd ${CZERO_PATH}/build
#./depends.sh
#cmake ..
#make clean
#make czero
CZERO_IMPT_PATH=${LOCAL_PATH}/../../../go-czero-import
if [ ! -d ${CZERO_IMPT_PATH} ]; then
echo "the path ${CZERO_IMPT_PATH} should be available for build czero"
Expand Down
11 changes: 4 additions & 7 deletions build/package/startup-alpha.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/bin/bash
PACKAGEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:~/working/czero/lib/
rm -rf ~/working/*
cp -rf ${PACKAGEDIR}/* ~/working/
cd ~/working
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PACKAGEDIR}/czero/lib/
RPCPORT=8545
SERVERPORT=60602
RPCADDR=$(hostname -I|awk -F ' ' '{print $1}')
RPCAPI='sero,web3'
DATADIR='~/.datadir'
LOGDIR='../.log'
DATADIR="${PACKAGEDIR}/../datadir"
LOGDIR="${PACKAGEDIR}/../log"
PATTERN_MAIN_PROCESS="gero.*datadir="
killProcess() {
if [[ -z $1 ]]; then
Expand All @@ -26,4 +23,4 @@ if [ ! -d ${LOGDIR} ]; then
fi
killProcess ${PATTERN_MAIN_PROCESS}
sleep 10
nohup ~/working/bin/gero --alpha --datadir=${DATADIR} --rpc --rpcport ${RPCPORT} --rpcaddr ${RPCADDR} --rpcapi ${RPCAPI} --port ${SERVERPORT} --rpccorsdomain "*" &> ${LOGDIR}/gero.log &
nohup ${PACKAGEDIR}/bin/gero --alpha --datadir=${DATADIR} --rpc --rpcport ${RPCPORT} --rpcaddr ${RPCADDR} --rpcapi ${RPCAPI} --port ${SERVERPORT} --rpccorsdomain "*" &> ${LOGDIR}/gero.log &
11 changes: 4 additions & 7 deletions build/package/startup-beta.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/bin/bash
PACKAGEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:~/working/czero/lib/
rm -rf ~/working/*
cp -rf ${PACKAGEDIR}/* ~/working/
cd ~/working
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PACKAGEDIR}/czero/lib/
RPCPORT=8545
SERVERPORT=60602
RPCADDR=$(hostname -I|awk -F ' ' '{print $1}')
RPCAPI='sero,web3'
DATADIR='~/.datadir'
LOGDIR='../.log'
DATADIR="${PACKAGEDIR}/../datadir"
LOGDIR="${PACKAGEDIR}/../log"
PATTERN_MAIN_PROCESS="gero.*datadir="
killProcess() {
if [[ -z $1 ]]; then
Expand All @@ -26,4 +23,4 @@ if [ ! -d ${LOGDIR} ]; then
fi
killProcess ${PATTERN_MAIN_PROCESS}
sleep 10
nohup ~/working/bin/gero --datadir=${DATADIR} --rpc --rpcport ${RPCPORT} --rpcaddr ${RPCADDR} --rpcapi ${RPCAPI} --port ${SERVERPORT} --rpccorsdomain "*" &> ${LOGDIR}/gero.log &
nohup ${PACKAGEDIR}/bin/gero --datadir=${DATADIR} --rpc --rpcport ${RPCPORT} --rpcaddr ${RPCADDR} --rpcapi ${RPCAPI} --port ${SERVERPORT} --rpccorsdomain "*" &> ${LOGDIR}/gero.log &
35 changes: 23 additions & 12 deletions cmd/gero/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"fmt"
"github.com/sero-cash/go-czero-import/cpt"
"math"
"os"
"runtime"
Expand All @@ -28,12 +27,14 @@ import (
"strconv"
"strings"
"time"


"github.com/sero-cash/go-czero-import/cpt"

"gopkg.in/urfave/cli.v1"

"github.com/sero-cash/go-sero/common/base58"
"github.com/sero-cash/go-sero/zero/zconfig"

"github.com/elastic/gosigar"
"github.com/sero-cash/go-sero/accounts"
"github.com/sero-cash/go-sero/accounts/keystore"
Expand Down Expand Up @@ -188,15 +189,25 @@ func init() {
app.Flags = append(app.Flags, metricsFlags...)

app.Before = func(ctx *cli.Context) error {
netType:=cpt.NET_Beta
switch {
case ctx.GlobalBool(utils.AlphanetFlag.Name):
netType=cpt.NET_Alpha
case ctx.GlobalBool(utils.DeveloperFlag.Name):
netType=cpt.NET_Dev

subCommandName := ""

if len(ctx.Args()) > 0 {
subCommandName = ctx.Args()[0]
}

if !strings.EqualFold(subCommandName, "attach") {
netType := cpt.NET_Beta
switch {
case ctx.GlobalBool(utils.AlphanetFlag.Name):
netType = cpt.NET_Alpha
case ctx.GlobalBool(utils.DeveloperFlag.Name):
netType = cpt.NET_Dev
}
cpt.ZeroInit(netType)

}
cpt.ZeroInit(netType)


runtime.GOMAXPROCS(runtime.NumCPU())

logdir := ""
Expand Down
Loading

0 comments on commit 9cbc8c1

Please sign in to comment.