Skip to content

Commit

Permalink
refactor: cmd follows the new aeternity split
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Oct 10, 2019
1 parent 3638ebd commit 329766b
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 116 deletions.
29 changes: 16 additions & 13 deletions cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import (
"runtime"
"sync"

"github.com/aeternity/aepp-sdk-go/v5/aeternity"
"github.com/aeternity/aepp-sdk-go/account"
"github.com/aeternity/aepp-sdk-go/config"
"github.com/aeternity/aepp-sdk-go/models"
"github.com/aeternity/aepp-sdk-go/naet"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -71,7 +74,7 @@ func addressFunc(cmd *cobra.Command, args []string) error {
}

// load the account
account, err := aeternity.LoadAccountFromKeyStoreFile(args[0], p)
account, err := account.LoadAccountFromKeyStoreFile(args[0], p)
if err != nil {
return err
}
Expand All @@ -96,22 +99,22 @@ var createCmd = &cobra.Command{
}

func createFunc(cmd *cobra.Command, args []string) (err error) {
account, _ := aeternity.NewAccount()
acc, _ := account.NewAccount()
p, err := getPassword()
if err != nil {
return err
}
accountFileName = args[0]

// check if a name was given
f, err := aeternity.StoreAccountToKeyStoreFile(account, p, accountFileName)
f, err := account.StoreAccountToKeyStoreFile(acc, p, accountFileName)
if err != nil {
return err
}

Pp(
"Wallet path", f,
"Account address", account.Address,
"Account address", acc.Address,
)

return nil
Expand All @@ -129,11 +132,11 @@ var balanceCmd = &cobra.Command{
},
}

func balanceFunc(conn aeternity.GetAccounter, args []string) (err error) {
func balanceFunc(conn naet.GetAccounter, args []string) (err error) {
p, err := getPassword()

// load the account
account, err := aeternity.LoadAccountFromKeyStoreFile(args[0], p)
account, err := account.LoadAccountFromKeyStoreFile(args[0], p)
if err != nil {
return err
}
Expand All @@ -160,18 +163,18 @@ func signFunc(cmd *cobra.Command, args []string) (err error) {
p, err := getPassword()

// load the account
account, err := aeternity.LoadAccountFromKeyStoreFile(args[0], p)
account, err := account.LoadAccountFromKeyStoreFile(args[0], p)
if err != nil {
return err
}

txUnsignedBase64 := args[1]
tx, err := aeternity.DeserializeTxStr(txUnsignedBase64)
tx, err := models.DeserializeTxStr(txUnsignedBase64)
if err != nil {
return err
}

txSignedBase64, txHash, signature, err := aeternity.SignHashTx(account, tx, aeternity.Config.Node.NetworkID)
txSignedBase64, txHash, signature, err := models.SignHashTx(account, tx, config.Config.Node.NetworkID)
if err != nil {
return err
}
Expand All @@ -197,14 +200,14 @@ var saveCmd = &cobra.Command{

func saveFunc(cmd *cobra.Command, args []string) (err error) {
accountFileName := args[0]
account, err := aeternity.AccountFromHexString(args[1])
acc, err := account.AccountFromHexString(args[1])
if err != nil {
return err
}

p, err := getPassword()

f, err := aeternity.StoreAccountToKeyStoreFile(account, p, accountFileName)
f, err := account.StoreAccountToKeyStoreFile(acc, p, accountFileName)
if err != nil {
return err
}
Expand Down Expand Up @@ -241,7 +244,7 @@ func vanityFunc(cmd *cobra.Command, args []string) {
for i := 0; i < runtime.NumCPU(); i++ {
go func() {
for {
a, _ := aeternity.NewAccount()
a, _ := account.NewAccount()

if r.MatchString(a.Address[3:]) {
fmt.Println("FOUND!")
Expand Down
4 changes: 2 additions & 2 deletions cmd/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"testing"

"github.com/aeternity/aepp-sdk-go/v5/aeternity"
"github.com/aeternity/aepp-sdk-go/naet"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -75,7 +75,7 @@ func TestAccountSign(t *testing.T) {
func Test_balanceFunc(t *testing.T) {
setPrivateNetParams()
type args struct {
conn aeternity.GetAccounter
conn naet.GetAccounter
args []string
accountPrivateKey string
password string
Expand Down
24 changes: 13 additions & 11 deletions cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
"errors"
"fmt"

"github.com/aeternity/aepp-sdk-go/v5/aeternity"
"github.com/aeternity/aepp-sdk-go/binary"
"github.com/aeternity/aepp-sdk-go/config"
"github.com/aeternity/aepp-sdk-go/naet"
"github.com/spf13/cobra"
)

Expand All @@ -39,7 +41,7 @@ var topCmd = &cobra.Command{
},
}

func topFunc(conn aeternity.GetTopBlocker, args []string) error {
func topFunc(conn naet.GetTopBlocker, args []string) error {
v, err := conn.GetTopBlock()
if err != nil {
return err
Expand All @@ -58,7 +60,7 @@ var statusCmd = &cobra.Command{
},
}

func statusFunc(conn aeternity.GetStatuser, args []string) (err error) {
func statusFunc(conn naet.GetStatuser, args []string) (err error) {
v, err := conn.GetStatus()
if err != nil {
return err
Expand All @@ -79,7 +81,7 @@ var playCmd = &cobra.Command{
}

type playFuncInterface interface {
aeternity.GetHeighter
naet.GetHeighter
getGenerationMicroBlockTransactioner
}

Expand Down Expand Up @@ -126,7 +128,7 @@ var broadcastCmd = &cobra.Command{
},
}

func broadcastFunc(conn aeternity.PostTransactioner, args []string) (err error) {
func broadcastFunc(conn naet.PostTransactioner, args []string) (err error) {
// Load variables from arguments
txSignedBase64 := args[0]

Expand All @@ -136,15 +138,15 @@ func broadcastFunc(conn aeternity.PostTransactioner, args []string) (err error)
}

// Transform tx_ string back to an RLP bytearray to calculate its hash
txRLP, err := aeternity.Decode(txSignedBase64)
txRLP, err := binary.Decode(txSignedBase64)
if err != nil {
return err
}
rlpTxHashRaw, err := aeternity.Blake2bHash(txRLP)
rlpTxHashRaw, err := binary.Blake2bHash(txRLP)
if err != nil {
return err
}
signedEncodedTxHash := aeternity.Encode(aeternity.PrefixTransactionHash, rlpTxHashRaw)
signedEncodedTxHash := binary.Encode(binary.PrefixTransactionHash, rlpTxHashRaw)

err = conn.PostTransaction(txSignedBase64, signedEncodedTxHash)
if err != nil {
Expand All @@ -166,13 +168,13 @@ var ttlCmd = &cobra.Command{
},
}

func ttlFunc(conn aeternity.GetHeighter, args []string) (err error) {
func ttlFunc(conn naet.GetHeighter, args []string) (err error) {
height, err := conn.GetHeight()
if err != nil {
errFinal := fmt.Errorf("Error getting height from the node: %v", err)
return errFinal
}
ttl = height + aeternity.Config.Client.TTL
ttl = height + config.Config.Client.TTL
fmt.Println(ttl)
return nil
}
Expand All @@ -188,7 +190,7 @@ var networkIDCmd = &cobra.Command{
},
}

func networkIDFunc(conn aeternity.GetStatuser, args []string) (err error) {
func networkIDFunc(conn naet.GetStatuser, args []string) (err error) {
resp, err := conn.GetStatus()
if err != nil {
errFinal := fmt.Errorf("Error getting status information from the node: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions cmd/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/aeternity/aepp-sdk-go/v5/aeternity"
"github.com/aeternity/aepp-sdk-go/naet"
)

// Prefixing each test with Example makes go-test check the stdout
Expand All @@ -19,7 +19,7 @@ func init() {

func Test_topFunc(t *testing.T) {
type args struct {
conn aeternity.GetTopBlocker
conn naet.GetTopBlocker
args []string
}
tests := []struct {
Expand Down Expand Up @@ -63,7 +63,7 @@ func Test_topFunc(t *testing.T) {

func Test_broadcastFunc(t *testing.T) {
type args struct {
conn aeternity.PostTransactioner
conn naet.PostTransactioner
args []string
}
tests := []struct {
Expand Down Expand Up @@ -91,7 +91,7 @@ func Test_broadcastFunc(t *testing.T) {

func Test_statusFunc(t *testing.T) {
type args struct {
conn aeternity.GetStatuser
conn naet.GetStatuser
args []string
}
tests := []struct {
Expand Down Expand Up @@ -133,7 +133,7 @@ func Test_statusFunc(t *testing.T) {

func Test_ttlFunc(t *testing.T) {
type args struct {
conn aeternity.GetHeighter
conn naet.GetHeighter
args []string
}
tests := []struct {
Expand Down Expand Up @@ -161,7 +161,7 @@ func Test_ttlFunc(t *testing.T) {

func Test_networkIDFunc(t *testing.T) {
type args struct {
conn aeternity.GetStatuser
conn naet.GetStatuser
args []string
}
tests := []struct {
Expand Down
23 changes: 12 additions & 11 deletions cmd/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"io/ioutil"
"os"

"github.com/aeternity/aepp-sdk-go/v5/aeternity"
"github.com/aeternity/aepp-sdk-go/config"
"github.com/aeternity/aepp-sdk-go/naet"
"github.com/spf13/cobra"
)

Expand All @@ -28,13 +29,13 @@ var compileCmd = &cobra.Command{
SilenceUsage: true,
}

func compileFunc(conn aeternity.CompileContracter, args []string) (err error) {
func compileFunc(conn naet.CompileContracter, args []string) (err error) {
s, err := readSource(args[0])
if err != nil {
return err
}

bytecode, err := conn.CompileContract(s, aeternity.Config.Compiler.Backend)
bytecode, err := conn.CompileContract(s, config.Config.Compiler.Backend)
fmt.Println(bytecode)
return err
}
Expand All @@ -51,13 +52,13 @@ var encodeCalldataCmd = &cobra.Command{
SilenceUsage: true,
}

func encodeCalldataFunc(conn aeternity.EncodeCalldataer, args []string) (err error) {
func encodeCalldataFunc(conn naet.EncodeCalldataer, args []string) (err error) {
s, err := readSource(args[0])
if err != nil {
return err
}

callData, err := conn.EncodeCalldata(s, args[1], args[2:], aeternity.Config.Compiler.Backend)
callData, err := conn.EncodeCalldata(s, args[1], args[2:], config.Config.Compiler.Backend)
if err != nil {
return err
}
Expand All @@ -66,8 +67,8 @@ func encodeCalldataFunc(conn aeternity.EncodeCalldataer, args []string) (err err
}

type decodeCalldataer interface {
aeternity.DecodeCalldataBytecoder
aeternity.DecodeCalldataSourcer
naet.DecodeCalldataBytecoder
naet.DecodeCalldataSourcer
}

var decodeCalldataBytecodeCmd = &cobra.Command{
Expand All @@ -90,7 +91,7 @@ func decodeCalldataBytecodeFunc(conn decodeCalldataer, args []string) (err error
return fmt.Errorf("%s is not bytecode", args[0])
}

r, err := conn.DecodeCalldataBytecode(args[0], args[1], aeternity.Config.Compiler.Backend)
r, err := conn.DecodeCalldataBytecode(args[0], args[1], config.Config.Compiler.Backend)
if err != nil {
return
}
Expand Down Expand Up @@ -120,7 +121,7 @@ func decodeCalldataSourceFunc(conn decodeCalldataer, args []string) (err error)
return fmt.Errorf("%s is not bytecode", args[0])
}

r, err := conn.DecodeCalldataSource(source, args[1], args[2], aeternity.Config.Compiler.Backend)
r, err := conn.DecodeCalldataSource(source, args[1], args[2], config.Config.Compiler.Backend)

fmt.Println(*r.Function, r.Arguments)
return
Expand All @@ -138,13 +139,13 @@ var generateAciCmd = &cobra.Command{
SilenceUsage: true,
}

func generateAciFunc(conn aeternity.GenerateACIer, args []string) (err error) {
func generateAciFunc(conn naet.GenerateACIer, args []string) (err error) {
source, err := readSource(args[0])
if err != nil {
return
}

aci, err := conn.GenerateACI(source, aeternity.Config.Compiler.Backend)
aci, err := conn.GenerateACI(source, config.Config.Compiler.Backend)
if err != nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"os"
"testing"

"github.com/aeternity/aepp-sdk-go/v5/aeternity"
"github.com/aeternity/aepp-sdk-go/naet"
)

func Test_compileFunc(t *testing.T) {
type args struct {
conn aeternity.CompileContracter
conn naet.CompileContracter
source string
}
tests := []struct {
Expand Down Expand Up @@ -63,7 +63,7 @@ func Test_compileFunc(t *testing.T) {

func Test_encodeCalldataFunc(t *testing.T) {
type args struct {
conn aeternity.EncodeCalldataer
conn naet.EncodeCalldataer
args []string
source string
}
Expand Down Expand Up @@ -203,7 +203,7 @@ func Test_generateAciFunc(t *testing.T) {
tempdir, path := writeTestContractFile(t, contractSimpleStorage)
defer os.RemoveAll(tempdir)
type args struct {
conn aeternity.GenerateACIer
conn naet.GenerateACIer
args []string
}
tests := []struct {
Expand Down

0 comments on commit 329766b

Please sign in to comment.