"context"
log "github.com/sirupsen/logrus"
-
- "github.com/bytom/errors"
)
-var errCurrentToken = errors.New("token cannot delete itself")
-
func (bcr *BlockchainReactor) createAccessToken(ctx context.Context, x struct {
ID string `json:"id"`
Type string `json:"type"`
}) Response {
//TODO Add delete permission verify.
if err := bcr.accessTokens.Delete(ctx, x.ID); err != nil {
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
- return resWrapper(nil)
+ return NewSuccessResponse(nil)
}
func (bcr *BlockchainReactor) checkAccessToken(ctx context.Context, x struct {
gasrate := map[string]int64{"gasRate": validation.GasRate}
return NewSuccessResponse(gasrate)
}
-
-// wrapper json for response
-// Deprecated: We should use Response factor to create response
-func resWrapper(data interface{}, errWrapper ...error) Response {
- var response Response
-
- if errWrapper != nil {
- response = Response{Status: FAIL, Msg: errWrapper[0].Error()}
- } else {
- response = Response{Status: SUCCESS, Data: data}
- }
-
- return response
-}
tmpl, err := bcr.buildSingle(subctx, buildReqs)
if err != nil {
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
- return resWrapper(tmpl)
+ return NewSuccessResponse(tmpl)
}
func (bcr *BlockchainReactor) submitSingle(ctx context.Context, tpl *txbuilder.Template) (map[string]string, error) {
// POST /sign-submit-transaction
func (bcr *BlockchainReactor) signSubmit(ctx context.Context, x struct {
- Password []string `json:"password"`
- Txs txbuilder.Template `json:"transaction"`
+ Password []string `json:"password"`
+ Txs txbuilder.Template `json:"transaction"`
}) Response {
var err error
log "github.com/sirupsen/logrus"
- "github.com/bytom/blockchain/query"
"github.com/bytom/blockchain/txfeed"
"github.com/bytom/errors"
)
func (bcr *BlockchainReactor) getTxFeed(ctx context.Context, in struct {
Alias string `json:"alias,omitempty"`
}) Response {
- var txfeed interface{}
+ var tmpTxFeed interface{}
rawTxfeed, err := bcr.getTxFeedByAlias(ctx, in.Alias)
if err != nil {
return NewErrorResponse(err)
}
- err = json.Unmarshal(rawTxfeed, &txfeed)
+ err = json.Unmarshal(rawTxfeed, &tmpTxFeed)
if err != nil {
return NewErrorResponse(err)
}
- data := map[string]interface{}{"txfeed": txfeed}
+ data := map[string]interface{}{"txfeed": tmpTxFeed}
return NewSuccessResponse(data)
}
return NewSuccessResponse(nil)
}
-// txAfterIsBefore returns true if a is before b. It returns an error if either
-// a or b are not valid query.TxAfters.
-func txAfterIsBefore(a, b string) (bool, error) {
- aAfter, err := query.DecodeTxAfter(a)
- if err != nil {
- return false, err
- }
-
- bAfter, err := query.DecodeTxAfter(b)
- if err != nil {
- return false, err
- }
-
- return aAfter.FromBlockHeight < bAfter.FromBlockHeight ||
- (aAfter.FromBlockHeight == bAfter.FromBlockHeight &&
- aAfter.FromPosition < bAfter.FromPosition), nil
-}
-
func (bcr *BlockchainReactor) getTxFeeds() ([]txfeed.TxFeed, error) {
txFeed := txfeed.TxFeed{}
txFeeds := make([]txfeed.TxFeed, 0)
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
+
+ "github.com/bytom/blockchain"
"github.com/bytom/crypto/ed25519/chainkd"
"github.com/bytom/util"
- "github.com/bytom/blockchain"
)
var createKeyCmd = &cobra.Command{
var key = struct {
Alias string `json:"alias"`
Password string `json:"password"`
- }{Alias: args[0], Password: "123456"}
+ }{Alias: args[0], Password: args[1]}
data, exitCode := util.ClientCall("/create-key", &key)
if exitCode != util.Success {
var key = struct {
Password string
XPub chainkd.XPub `json:"xpubs"`
- }{XPub: *xpub, Password: "123456"}
+ }{XPub: *xpub, Password: args[1]}
if _, exitCode := util.ClientCall("/delete-key", &key); exitCode != util.Success {
os.Exit(exitCode)
buildTransactionCmd.PersistentFlags().BoolVar(&pretty, "pretty", false, "pretty print json result")
buildTransactionCmd.PersistentFlags().BoolVar(&alias, "alias", false, "use alias build transaction")
- signTransactionCmd.PersistentFlags().StringVarP(&password, "password", "p", "", "password of the account which sign these transaction(s)")
+ signTransactionCmd.PersistentFlags().StringArrayVarP(&password, "password", "p", []string{}, "password of the account which sign these transaction(s)")
signTransactionCmd.PersistentFlags().BoolVar(&pretty, "pretty", false, "pretty print json result")
- signSubTransactionCmd.PersistentFlags().StringVarP(&password, "password", "p", "", "password of the account which sign these transaction(s)")
+ signSubTransactionCmd.PersistentFlags().StringArrayVarP(&password, "password", "p", []string{}, "password of the account which sign these transaction(s)")
listTransactionsCmd.PersistentFlags().StringVar(&txID, "id", "", "transaction id")
listTransactionsCmd.PersistentFlags().StringVar(&account, "account_id", "", "account id")
btmGas = ""
receiverProgram = ""
address = ""
- password = ""
+ password = make([]string, 0)
pretty = false
alias = false
txID = ""
}
var req = struct {
- Auth string
- Txs txbuilder.Template `json:"transaction"`
- }{Auth: "123456", Txs: template}
+ Password []string `json:"password"`
+ Txs txbuilder.Template `json:"transaction"`
+ }{Password: password, Txs: template}
jww.FEEDBACK.Printf("\n\n")
data, exitCode := util.ClientCall("/sign-transaction", &req)
Short: "Sign and Submit transaction templates with account password",
Args: cobra.ExactArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
- // cmd.MarkFlagRequired("password")
+ cmd.MarkFlagRequired("password")
},
Run: func(cmd *cobra.Command, args []string) {
template := txbuilder.Template{}
}
var req = struct {
- Auth string
- Txs txbuilder.Template `json:"transaction"`
- }{Auth: "123456", Txs: template}
+ Password []string `json:"password"`
+ Txs txbuilder.Template `json:"transaction"`
+ }{Password: password, Txs: template}
jww.FEEDBACK.Printf("\n\n")
data, exitCode := util.ClientCall("/sign-submit-transaction", &req)
for {
hash := block.Hash()
if difficulty.CheckProofOfWork(&hash, block.Bits) {
- log.Info(block.Nonce)
+ log.WithField("block.Nonce=", block.Nonce).Info()
break
}
block.Nonce++