diff --git a/baseapp/data/kvstore.db/000002.log b/baseapp/data/kvstore.db/000002.log deleted file mode 100644 index e69de29..0000000 diff --git a/baseapp/data/kvstore.db/MANIFEST-000003 b/baseapp/data/kvstore.db/MANIFEST-000003 deleted file mode 100644 index 0a36c9e..0000000 Binary files a/baseapp/data/kvstore.db/MANIFEST-000003 and /dev/null differ diff --git a/client/utils/utils.go b/client/utils/utils.go index 0ef9e0e..4137233 100644 --- a/client/utils/utils.go +++ b/client/utils/utils.go @@ -4,7 +4,6 @@ import ( "github.com/QOSGroup/qbase/txs" "github.com/QOSGroup/qstars/client/context" "github.com/QOSGroup/qstars/wire" - "github.com/tendermint/tendermint/crypto/ed25519" ) // SendTx implements a auxiliary handler that facilitates sending a series of @@ -12,7 +11,7 @@ import ( // ensures that the account exists, has a proper number and sequence set. In // addition, it builds and signs a transaction with the supplied messages. // Finally, it broadcasts the signed transaction to a node. -func SendTx(cliCtx context.CLIContext, cdc *wire.Codec, txStd *txs.TxStd, priv ed25519.PrivKeyEd25519) (string, error) { +func SendTx(cliCtx context.CLIContext, cdc *wire.Codec, txStd *txs.TxStd) (string, error) { txBytes, err := cdc.MarshalBinaryBare(txStd) if err != nil { diff --git a/config/cliconfig.go b/config/cliconfig.go index ecd59f8..667ef29 100644 --- a/config/cliconfig.go +++ b/config/cliconfig.go @@ -18,7 +18,7 @@ type QStarsClientContext struct{ type CLIConfig struct { QOSChainID string `mapstructure:"qos_chain_id"` - ChainID string `mapstructure:"chain_id"` + QSCChainID string `mapstructure:"chain_id"` RootDir string `mapstructure:"home"` QOSNodeURI string `mapstructure:"qos_node_uri"` QSTARSNodeURI string `mapstructure:"qstars_node_uri"` @@ -62,7 +62,7 @@ func InterceptLoadConfig() (conf *CLIConfig, err error) { if _, err := os.Stat(configFilePath); os.IsNotExist(err) { // the following parse config is needed to create directories conf, _ = ParseConfig() - conf.ChainID = "abc" + conf.QSCChainID = "abc" conf.QOSNodeURI = "localhost:1317" conf.QSTARSNodeURI = "localhost:1317" WriteConfigFile(configFilePath, conf) diff --git a/go.mod b/go.mod index 39c4bf5..d33c5a5 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/QOSGroup/qstars require ( github.com/BurntSushi/toml v0.3.1 - github.com/QOSGroup/qbase v0.0.4 + github.com/QOSGroup/qbase v0.0.5 github.com/bartekn/go-bip39 v0.0.0-20171116152956-a05967ea095d github.com/bgentry/speakeasy v0.1.0 github.com/brejski/hid v0.0.0-20180408220029-06112dcfcc50 // indirect diff --git a/x/bank/bankstub.go b/x/bank/bankstub.go index 32e7958..9b0628c 100644 --- a/x/bank/bankstub.go +++ b/x/bank/bankstub.go @@ -8,6 +8,7 @@ import ( go_amino "github.com/tendermint/go-amino" "github.com/QOSGroup/qbase/types" "github.com/QOSGroup/qbase/context" + "github.com/QOSGroup/qbase/example/basecoin/tx" ) type BankStub struct { @@ -26,7 +27,8 @@ func (kv BankStub) StartX(base *baseapp.QstarsBaseApp) error{ } func (kv BankStub) RegisterKVCdc(cdc *go_amino.Codec) { - cdc.RegisterConcrete(&SendTx{}, "basecoin/SendTx",nil) + cdc.RegisterConcrete(&tx.SendTx{}, "basecoin/SendTx",nil) + cdc.RegisterConcrete(&WrapperSendTx{}, "qstars/WrapperSendTx",nil) cdc.RegisterConcrete(&bctypes.AppAccount{}, "basecoin/AppAccount", nil) } diff --git a/x/bank/handler.go b/x/bank/handler.go index 98b788b..6956b10 100644 --- a/x/bank/handler.go +++ b/x/bank/handler.go @@ -1,34 +1,31 @@ package bank import ( - "bytes" "fmt" + "github.com/QOSGroup/qbase/context" "github.com/QOSGroup/qbase/txs" btypes "github.com/QOSGroup/qbase/types" - "github.com/QOSGroup/qbase/context" + "github.com/tendermint/tendermint/types" + "strconv" ) -type SendTx struct { - From btypes.Address `json:"from"` - To btypes.Address `json:"to"` - Coin btypes.BaseCoin `json:"coin"` +type WrapperSendTx struct { + Wrapper *txs.TxStd } -var _ txs.ITx = (*SendTx)(nil) +var _ txs.ITx = (*WrapperSendTx)(nil) -func NewSendTx(from btypes.Address, to btypes.Address, coin btypes.BaseCoin) SendTx { - return SendTx{From: from, To: to, Coin: coin} +func NewWrapperSendTx(wrapper *txs.TxStd) WrapperSendTx { + return WrapperSendTx{Wrapper: wrapper} } -func (tx SendTx) ValidateData(ctx context.Context) bool { - if len(tx.From) == 0 || len(tx.To) == 0 || btypes.NewInt(0).GT(tx.Coin.Amount) { - return false - } +func (tx WrapperSendTx) ValidateData(ctx context.Context) bool { + return true } -func (tx SendTx) Exec(ctx context.Context) (result btypes.Result, crossTxQcps *txs.TxQcp) { +func (tx WrapperSendTx) Exec(ctx context.Context) (result btypes.Result, crossTxQcps *txs.TxQcp) { result = btypes.Result{ Code: btypes.ABCICodeOK, } @@ -40,13 +37,14 @@ func (tx SendTx) Exec(ctx context.Context) (result btypes.Result, crossTxQcps *t } crossTxQcps = &cross - tt := txs.TxStd{ - } + heigth1 := strconv.FormatInt(ctx.BlockHeight(),10) + tx1 := (types.Tx (ctx.TxBytes())).String() + + fmt.Println(" heigth: " + heigth1 + " hash:" + tx1) - tt.ITx = tx - crossTxQcps.TxStd = &tt - crossTxQcps.To = "basecoin-chain" + crossTxQcps.TxStd = tx.Wrapper + crossTxQcps.To = "main-chain" r := btypes.Result{ Code:0, @@ -54,22 +52,18 @@ func (tx SendTx) Exec(ctx context.Context) (result btypes.Result, crossTxQcps *t return r, &cross } -func (tx SendTx) GetSigner() []btypes.Address { - return []btypes.Address{tx.From} +func (tx WrapperSendTx) GetSigner() []btypes.Address { + return nil } -func (tx SendTx) CalcGas() btypes.BigInt { +func (tx WrapperSendTx) CalcGas() btypes.BigInt { return btypes.ZeroInt() } -func (tx SendTx) GetGasPayer() btypes.Address { - return tx.From +func (tx WrapperSendTx) GetGasPayer() btypes.Address { + return nil } -func (tx SendTx) GetSignData() []byte { - var buf bytes.Buffer - buf.Write(tx.From) - buf.Write(tx.To) - buf.Write([]byte(tx.Coin.String())) - return buf.Bytes() +func (tx WrapperSendTx) GetSignData() []byte { + return nil } diff --git a/x/bank/process.go b/x/bank/process.go index d6f5f04..d7f6e7b 100644 --- a/x/bank/process.go +++ b/x/bank/process.go @@ -3,6 +3,7 @@ package bank import ( + "github.com/QOSGroup/qbase/example/basecoin/tx" "github.com/QOSGroup/qbase/account" "github.com/QOSGroup/qbase/txs" "github.com/QOSGroup/qstars/client/context" @@ -53,26 +54,19 @@ func NewSendOptions(opts ...func(*SendOptions)) *SendOptions { } func Send(cdc *wire.Codec, fromstr string, to qbasetypes.Address, coins types.Coins, sopt *SendOptions) (*SendResult, error) { - - _, addrben32, priv:= utility.PubAddrRetrieval(fromstr,cdc) - - - from, err := types.AccAddressFromBech32(addrben32) key := account.AddressStoreKey(from) if err != nil { return nil, err } - var chainID string + directTOQOS := config.GetCLIContext().Config.DirectTOQOS var cliCtx context.CLIContext if directTOQOS==true{ cliCtx = *config.GetCLIContext().QOSCliContext - chainID = config.GetCLIContext().Config.QOSChainID }else { cliCtx = *config.GetCLIContext().QSCCliContext - chainID = config.GetCLIContext().Config.ChainID } account, err := config.GetCLIContext().QOSCliContext.GetAccount(key,cdc) @@ -101,24 +95,29 @@ func Send(cdc *wire.Codec, fromstr string, to qbasetypes.Address, coins types.Co } var nn int64 + nn = int64(account.Nonce) + //if directTOQOS==true { + // nn = int64(account.Nonce) + //}else { + // qscaccount, err := config.GetCLIContext().QSCCliContext.GetAccount(key,cdc) + // if err != nil{ + // if err.Error()=="Account is not exsit." { + // nn = int64(0) + // }else{ + // return nil,err + // } + // }else{ + // nn = int64(qscaccount.Nonce) + // } + //} + nn++ + var msg *txs.TxStd if directTOQOS==true { - nn = int64(account.Nonce) - }else { - qscaccount, err := config.GetCLIContext().QSCCliContext.GetAccount(key,cdc) - if err != nil{ - if err.Error()=="Account is not exsit." { - nn = int64(0) - }else{ - return nil,err - } - }else{ - nn = int64(qscaccount.Nonce) - } + msg = genStdSendTx(cdc, from, to, cc, priv, nn) + }else{ + msg = genStdWrapTx(cdc, from, to, cc, priv, nn) } - nn++ - - msg := genStdSendTx(cdc,from,to,cc,priv,nn,chainID) - response, err := utils.SendTx(cliCtx, cdc,msg,priv) + response, err := utils.SendTx(cliCtx, cdc,msg) result := &SendResult{} result.Hash = response @@ -127,10 +126,10 @@ func Send(cdc *wire.Codec, fromstr string, to qbasetypes.Address, coins types.Co } func genStdSendTx(cdc *amino.Codec, sender qbasetypes.Address, receiver qbasetypes.Address, coin qbasetypes.BaseCoin, - priKey ed25519.PrivKeyEd25519, nonce int64, chainid string) *txs.TxStd { - sendTx := NewSendTx(sender, receiver, coin) + priKey ed25519.PrivKeyEd25519, nonce int64) *txs.TxStd { + sendTx := tx.NewSendTx(sender, receiver, coin) gas := qbasetypes.NewInt(int64(0)) - tx := txs.NewTxStd(&sendTx, chainid, gas) + tx := txs.NewTxStd(&sendTx, config.GetCLIContext().Config.QOSChainID, gas) //priHex, _ := hex.DecodeString(senderPriHex[2:]) //var priKey ed25519.PrivKeyEd25519 //cdc.MustUnmarshalBinaryBare(priHex, &priKey) @@ -143,3 +142,24 @@ func genStdSendTx(cdc *amino.Codec, sender qbasetypes.Address, receiver qbasetyp return tx } + +func genStdWrapTx(cdc *amino.Codec, sender qbasetypes.Address, receiver qbasetypes.Address, coin qbasetypes.BaseCoin, + priKey ed25519.PrivKeyEd25519, nonce int64 ) *txs.TxStd { + sendTx := tx.NewSendTx(sender, receiver, coin) + gas := qbasetypes.NewInt(int64(0)) + tx := txs.NewTxStd(&sendTx, config.GetCLIContext().Config.QOSChainID, gas) + //priHex, _ := hex.DecodeString(senderPriHex[2:]) + //var priKey ed25519.PrivKeyEd25519 + //cdc.MustUnmarshalBinaryBare(priHex, &priKey) + signature, _ := tx.SignTx(priKey, nonce) + tx.Signature = []txs.Signature{txs.Signature{ + Pubkey: priKey.PubKey(), + Signature: signature, + Nonce: nonce, + }} + + + tx2 := txs.NewTxStd(&sendTx, config.GetCLIContext().Config.QSCChainID, gas) + tx2.ITx = NewWrapperSendTx(tx) + return tx2 +} diff --git a/x/kvstore/process.go b/x/kvstore/process.go index 29ebe9d..dd9bfe5 100644 --- a/x/kvstore/process.go +++ b/x/kvstore/process.go @@ -76,7 +76,7 @@ func SendKV(cdc *wire.Codec, privateKey, key, value string, option *SendKVOption txStd := wrapToStdTx(key, value, option.chainID) - hash, err := utils.SendTx(cliCtx, cdc, txStd, priv) + hash, err := utils.SendTx(cliCtx, cdc, txStd) if err != nil { return nil, err }