Skip to content
Open
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

keystore/
client.db
bazo-client
bazo-client
*.key
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ Contents of `configuration.json`:
"bootstrap_server": {
"ip": "127.0.0.1",
"port": "8000"
},
"multisig_server": {
"ip": "127.0.0.1",
"port": "8020"
}
}
```
Expand Down Expand Up @@ -118,13 +114,12 @@ Options
* `--from`: The file to load the sender's private key from
* `--to`: The file to load the recipient's public key from
* `--toAddress`: Instead of passing the recipient's address by file with `--to`, you can also directly pass the recipient's address with this option
* `--multisig`: (optional) The file to load the multisig's private key from.

Examples

```bash
bazo-client funds --from myaccount.txt --to recipient.txt --txcount 0 --amount 100
bazo-client funds --from myaccount.txt --to recipient.txt --txcount 1 --amount 100 --multisig myaccount.txt
bazo-client funds --from myaccount.txt --to recipient.txt --txcount 1 --amount 100
bazo-client funds --from myaccount.txt --toAddress b978...<120 byte omitted>...e86ba --txcount 2 --amount 100 --fee 15
```

Expand Down
40 changes: 17 additions & 23 deletions REST/EPTransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ type Content struct {
Detail interface{} `json:"detail,omitempty"`
}

func CreateAccTxEndpoint(w http.ResponseWriter, req *http.Request) {
func CreateContractTxEndpoint(w http.ResponseWriter, req *http.Request) {
logger.Println("Incoming createAcc request")

params := mux.Vars(req)

header, _ := strconv.Atoi(params["header"])
fee, _ := strconv.Atoi(params["fee"])

tx := protocol.AccTx{
tx := protocol.ContractTx{
Header: byte(header),
Fee: uint64(fee),
}
Expand All @@ -49,26 +49,26 @@ func CreateAccTxEndpoint(w http.ResponseWriter, req *http.Request) {
copy(tx.PubKey[32:], newAccAddress.PublicKey.Y.Bytes())

txHash := tx.Hash()
client.UnsignedAccTx[txHash] = &tx
client.UnsignedContractTx[txHash] = &tx

var content []Content
content = append(content, Content{"PubKey1", hex.EncodeToString(tx.PubKey[:32])})
content = append(content, Content{"PubKey2", hex.EncodeToString(tx.PubKey[32:])})
content = append(content, Content{"PrivKey", hex.EncodeToString(newAccAddress.D.Bytes())})
content = append(content, Content{"TxHash", hex.EncodeToString(txHash[:])})

SendJsonResponse(w, JsonResponse{http.StatusOK, "AccTx successfully created.", content})
SendJsonResponse(w, JsonResponse{http.StatusOK, "ContractTx successfully created.", content})
}

func CreateAccTxEndpointWithPubKey(w http.ResponseWriter, req *http.Request) {
func CreateContractTxEndpointWithPubKey(w http.ResponseWriter, req *http.Request) {
logger.Println("Incoming createAcc request")

params := mux.Vars(req)

header, _ := strconv.Atoi(params["header"])
fee, _ := strconv.Atoi(params["fee"])

tx := protocol.AccTx{
tx := protocol.ContractTx{
Header: byte(header),
Fee: uint64(fee),
}
Expand All @@ -79,11 +79,11 @@ func CreateAccTxEndpointWithPubKey(w http.ResponseWriter, req *http.Request) {
copy(tx.Issuer[:], issuerInt.Bytes())

txHash := tx.Hash()
client.UnsignedAccTx[txHash] = &tx
client.UnsignedContractTx[txHash] = &tx

var content []Content
content = append(content, Content{"TxHash", hex.EncodeToString(txHash[:])})
SendJsonResponse(w, JsonResponse{http.StatusOK, "AccTx successfully created.", content})
SendJsonResponse(w, JsonResponse{http.StatusOK, "ContractTx successfully created.", content})
}

func CreateConfigTxEndpoint(w http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -137,8 +137,8 @@ func CreateFundsTxEndpoint(w http.ResponseWriter, req *http.Request) {
Amount: uint64(amount),
Fee: uint64(fee),
TxCnt: uint32(txCnt),
From: protocol.SerializeHashContent(fromPub),
To: protocol.SerializeHashContent(toPub),
From: fromPub,
To: toPub,
}

txHash := tx.Hash()
Expand Down Expand Up @@ -166,7 +166,7 @@ func sendTxEndpoint(w http.ResponseWriter, req *http.Request, txType int) {

switch txType {
case p2p.ACCTX_BRDCST:
if tx := client.UnsignedAccTx[txHash]; tx != nil {
if tx := client.UnsignedContractTx[txHash]; tx != nil {
tx.Sig = txSign
err = network.SendTx(util.Config.BootstrapIpport, tx, p2p.ACCTX_BRDCST)

Expand All @@ -189,17 +189,11 @@ func sendTxEndpoint(w http.ResponseWriter, req *http.Request, txType int) {
}
case p2p.FUNDSTX_BRDCST:
if tx := client.UnsignedFundsTx[txHash]; tx != nil {
if tx.Sig1 == [64]byte{} {
tx.Sig1 = txSign
err = network.SendTx(util.Config.MultisigIpport, tx, p2p.FUNDSTX_BRDCST)
if err != nil {
delete(client.UnsignedFundsTx, txHash)
}
} else {
tx.Sig2 = txSign
err = network.SendTx(util.Config.BootstrapIpport, tx, p2p.FUNDSTX_BRDCST)
delete(client.UnsignedFundsTx, txHash)
}
tx.Sig = txSign
err = network.SendTx(util.Config.BootstrapIpport, tx, p2p.FUNDSTX_BRDCST)

//If tx was successful or not, delete it from map either way. A new tx creation is the only option to repeat.
delete(client.UnsignedFundsTx, txHash)
} else {
logger.Printf("No transaction with hash %x found to sign\n", txHash)
SendJsonResponse(w, JsonResponse{http.StatusInternalServerError, fmt.Sprintf("No transaction with hash %x found to sign", txHash), nil})
Expand All @@ -215,7 +209,7 @@ func sendTxEndpoint(w http.ResponseWriter, req *http.Request, txType int) {
}
}

func SendAccTxEndpoint(w http.ResponseWriter, req *http.Request) {
func SendContractTxEndpoint(w http.ResponseWriter, req *http.Request) {
sendTxEndpoint(w, req, p2p.ACCTX_BRDCST)
}

Expand Down
6 changes: 3 additions & 3 deletions REST/REST.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func Init() {
func getEndpoints(router *mux.Router) {
router.HandleFunc("/account/{id}", GetAccountEndpoint).Methods("GET")

router.HandleFunc("/createAccTx/{header}/{fee}/{issuer}", CreateAccTxEndpoint).Methods("POST")
router.HandleFunc("/createAccTx/{pubKey}/{header}/{fee}/{issuer}", CreateAccTxEndpointWithPubKey).Methods("POST")
router.HandleFunc("/sendAccTx/{txHash}/{txSign}", SendAccTxEndpoint).Methods("POST")
router.HandleFunc("/createContractTx/{header}/{fee}/{issuer}", CreateContractTxEndpoint).Methods("POST")
router.HandleFunc("/createContractTx/{pubKey}/{header}/{fee}/{issuer}", CreateContractTxEndpointWithPubKey).Methods("POST")
router.HandleFunc("/sendContractTx/{txHash}/{txSign}", SendContractTxEndpoint).Methods("POST")

router.HandleFunc("/createConfigTx/{header}/{id}/{payload}/{fee}/{txCnt}", CreateConfigTxEndpoint).Methods("POST")
router.HandleFunc("/sendConfigTx/{txHash}/{txSign}", SendConfigTxEndpoint).Methods("POST")
Expand Down
95 changes: 63 additions & 32 deletions cli/account.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,87 @@
package cli

import (
"fmt"
"github.com/bazo-blockchain/bazo-client/network"
"github.com/bazo-blockchain/bazo-client/util"
"github.com/bazo-blockchain/bazo-miner/p2p"
"github.com/bazo-blockchain/bazo-miner/protocol"
"errors"
"github.com/bazo-blockchain/bazo-client/client"
"github.com/bazo-blockchain/bazo-miner/crypto"
"github.com/urfave/cli"
"log"
"math/big"
)

var (
headerFlag = cli.IntFlag {
Name: "header",
Usage: "header flag",
Value: 0,
}

feeFlag = cli.Uint64Flag {
Name: "fee",
Usage: "specify the fee",
Value: 1,
}

rootkeyFlag = cli.StringFlag {
Name: "rootwallet",
Usage: "load root's public private key from `FILE`",
}
)
type accountArgs struct {
address string
walletFile string
}

func GetAccountCommand(logger *log.Logger) cli.Command {
return cli.Command {
Name: "account",
Usage: "account management",
Subcommands: []cli.Command {
getCheckAccountCommand(logger),
getCreateAccountCommand(logger),
getAddAccountCommand(logger),
Action: func(c *cli.Context) error {
client.Init()

args := &accountArgs{
address: c.String("address"),
walletFile: c.String("wallet"),
}

return checkAccount(args, logger)
},
Flags: []cli.Flag {
cli.StringFlag {
Name: "address",
Usage: "the account's 128 byte address",
},
cli.StringFlag {
Name: "wallet",
Usage: "load the account's 128 byte address from `FILE`",
Value: "wallet.txt",
},
},
}
}

func checkAccount(args *accountArgs, logger *log.Logger) error {
err := args.ValidateInput()
if err != nil {
return err
}

var address [64]byte
if len(args.address) == 128 {
newPubInt, _ := new(big.Int).SetString(args.address, 16)
copy(address[:], newPubInt.Bytes())
} else {
privKey, err := crypto.ExtractECDSAKeyFromFile(args.walletFile)
if err != nil {
logger.Printf("%v\n", err)
return err
}

address = crypto.GetAddressFromPubKey(&privKey.PublicKey)
}

func sendAccountTx(tx protocol.Transaction, logger *log.Logger) error {
fmt.Printf("chash: %x\n", tx.Hash())
logger.Printf("My address: %x\n", address)

if err := network.SendTx(util.Config.BootstrapIpport, tx, p2p.ACCTX_BRDCST); err != nil {
logger.Printf("%v\n", err)
acc, _, err := client.CheckAccount(address)
if err != nil {
logger.Println(err)
return err
} else {
logger.Printf("Transaction successfully sent to network:\nTxHash: %x%v", tx.Hash(), tx)
logger.Printf(acc.String())
}

return nil
}

func (args accountArgs) ValidateInput() error {
if len(args.address) == 0 && len(args.walletFile) == 0 {
return errors.New("argument missing: address or wallet")
}

if len(args.walletFile) == 0 && len(args.address) != 128 {
return errors.New("invalid argument: address")
}

return nil
Expand Down
86 changes: 0 additions & 86 deletions cli/add.go

This file was deleted.

Loading