Skip to content

Commit

Permalink
refactor: Client{} API* methods renamed to not have an API prefix. Se…
Browse files Browse the repository at this point in the history
…e Dave Cheney's advice on naming
  • Loading branch information
randomshinichi committed Jul 4, 2019
1 parent 5710128 commit 6610ae8
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 52 deletions.
59 changes: 28 additions & 31 deletions aeternity/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import (
"github.com/aeternity/aepp-sdk-go/generated/models"
)

// Ae.API*() methods are the stable interface to Go code that uses this SDK.
// Logic implementation is handled by the unexported functions.

// APIGetStatus post transaction
func (ae *Client) APIGetStatus() (status *models.Status, err error) {
// GetStatus post transaction
func (ae *Client) GetStatus() (status *models.Status, err error) {
return getStatus(ae)
}

Expand All @@ -24,8 +21,8 @@ func getStatus(node *Client) (status *models.Status, err error) {
return
}

// APIPostTransaction post transaction
func (ae *Client) APIPostTransaction(signedEncodedTx, signedEncodedTxHash string) (err error) {
// PostTransaction post transaction
func (ae *Client) PostTransaction(signedEncodedTx, signedEncodedTxHash string) (err error) {
return postTransaction(ae, signedEncodedTx, signedEncodedTxHash)
}

Expand All @@ -44,13 +41,13 @@ func postTransaction(node *Client, signedEncodedTx, signedEncodedTxHash string)
return
}

// APIGetTopBlock get the top block of the chain
func (ae *Client) APIGetTopBlock() (kb *models.KeyBlockOrMicroBlockHeader, err error) {
// GetTopBlock get the top block of the chain
func (ae *Client) GetTopBlock() (kb *models.KeyBlockOrMicroBlockHeader, err error) {
return getTopBlock(ae)
}

// APIGetHeight get the height of the chain
func (ae *Client) APIGetHeight() (height uint64, err error) {
// GetHeight get the height of the chain
func (ae *Client) GetHeight() (height uint64, err error) {
tb, err := getTopBlock(ae)
if err != nil {
return
Expand All @@ -75,8 +72,8 @@ func getTopBlock(node *Client) (kb *models.KeyBlockOrMicroBlockHeader, err error
return
}

// APIGetCurrentKeyBlock get current key block
func (ae *Client) APIGetCurrentKeyBlock() (kb *models.KeyBlock, err error) {
// GetCurrentKeyBlock get current key block
func (ae *Client) GetCurrentKeyBlock() (kb *models.KeyBlock, err error) {
return getCurrentKeyBlock(ae)
}

Expand All @@ -90,8 +87,8 @@ func getCurrentKeyBlock(node *Client) (kb *models.KeyBlock, err error) {
return
}

// APIGetAccount return the account
func (ae *Client) APIGetAccount(accountID string) (account *models.Account, err error) {
// GetAccount return the account
func (ae *Client) GetAccount(accountID string) (account *models.Account, err error) {
return getAccount(ae, accountID)
}

Expand All @@ -108,8 +105,8 @@ func getAccount(node *Client, accountID string) (account *models.Account, err er
return
}

// APIGetNameEntryByName return the name entry
func (ae *Client) APIGetNameEntryByName(name string) (nameEntry *models.NameEntry, err error) {
// GetNameEntryByName return the name entry
func (ae *Client) GetNameEntryByName(name string) (nameEntry *models.NameEntry, err error) {
return getNameEntryByName(ae, name)
}

Expand All @@ -126,8 +123,8 @@ func getNameEntryByName(node *Client, name string) (nameEntry *models.NameEntry,
return
}

// APIGetMicroBlockTransactionsByHash get the transactions of a microblock
func (ae *Client) APIGetMicroBlockTransactionsByHash(microBlockID string) (txs *models.GenericTxs, err error) {
// GetMicroBlockTransactionsByHash get the transactions of a microblock
func (ae *Client) GetMicroBlockTransactionsByHash(microBlockID string) (txs *models.GenericTxs, err error) {
return getMicroBlockTransactionsByHash(ae, microBlockID)
}

Expand All @@ -142,8 +139,8 @@ func getMicroBlockTransactionsByHash(node *Client, microBlockID string) (txs *mo
return
}

// APIGetMicroBlockHeaderByHash get the header of a micro block
func (ae *Client) APIGetMicroBlockHeaderByHash(microBlockID string) (txs *models.MicroBlockHeader, err error) {
// GetMicroBlockHeaderByHash get the header of a micro block
func (ae *Client) GetMicroBlockHeaderByHash(microBlockID string) (txs *models.MicroBlockHeader, err error) {
return getMicroBlockHeaderByHash(ae, microBlockID)
}

Expand All @@ -158,8 +155,8 @@ func getMicroBlockHeaderByHash(node *Client, microBlockID string) (txs *models.M
return
}

// APIGetKeyBlockByHash get a key block by its hash
func (ae *Client) APIGetKeyBlockByHash(keyBlockID string) (txs *models.KeyBlock, err error) {
// GetKeyBlockByHash get a key block by its hash
func (ae *Client) GetKeyBlockByHash(keyBlockID string) (txs *models.KeyBlock, err error) {
return getKeyBlockByHash(ae, keyBlockID)
}

Expand All @@ -174,8 +171,8 @@ func getKeyBlockByHash(node *Client, keyBlockID string) (txs *models.KeyBlock, e
return
}

// APIGetTransactionByHash get a transaction by it's hash
func (ae *Client) APIGetTransactionByHash(txHash string) (tx *models.GenericSignedTx, err error) {
// GetTransactionByHash get a transaction by it's hash
func (ae *Client) GetTransactionByHash(txHash string) (tx *models.GenericSignedTx, err error) {
return getTransactionByHash(ae, txHash)
}

Expand All @@ -191,8 +188,8 @@ func getTransactionByHash(node *Client, txHash string) (tx *models.GenericSigned
return
}

// APIGetOracleByPubkey get an oracle by it's public key
func (ae *Client) APIGetOracleByPubkey(pubkey string) (oracle *models.RegisteredOracle, err error) {
// GetOracleByPubkey get an oracle by it's public key
func (ae *Client) GetOracleByPubkey(pubkey string) (oracle *models.RegisteredOracle, err error) {
return getOracleByPubkey(ae, pubkey)
}

Expand All @@ -208,8 +205,8 @@ func getOracleByPubkey(node *Client, pubkey string) (oracle *models.RegisteredOr
return
}

// APIGetOracleQueriesByPubkey get a list of queries made to a particular oracle
func (ae *Client) APIGetOracleQueriesByPubkey(pubkey string) (oracleQueries *models.OracleQueries, err error) {
// GetOracleQueriesByPubkey get a list of queries made to a particular oracle
func (ae *Client) GetOracleQueriesByPubkey(pubkey string) (oracleQueries *models.OracleQueries, err error) {
return getOracleQueriesByPubkey(ae, pubkey)
}

Expand All @@ -225,8 +222,8 @@ func getOracleQueriesByPubkey(node *Client, pubkey string) (oracleQueries *model
return
}

// APIGetContractByID gets a contract by ct_ ID
func (ae *Client) APIGetContractByID(ctID string) (contract *models.ContractObject, err error) {
// GetContractByID gets a contract by ct_ ID
func (ae *Client) GetContractByID(ctID string) (contract *models.ContractObject, err error) {
return getContractByID(ae, ctID)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func balanceFunc(cmd *cobra.Command, args []string) (err error) {
return err
}

a, err := aeCli.APIGetAccount(account.Address)
a, err := aeCli.GetAccount(account.Address)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var topCmd = &cobra.Command{

func topFunc(cmd *cobra.Command, args []string) (err error) {
aeCli := NewAeCli()
v, err := aeCli.APIGetTopBlock()
v, err := aeCli.GetTopBlock()
if err != nil {
return err
}
Expand All @@ -55,7 +55,7 @@ var statusCmd = &cobra.Command{

func statusFunc(cmd *cobra.Command, args []string) (err error) {
aeCli := NewAeCli()
v, err := aeCli.APIGetStatus()
v, err := aeCli.GetStatus()
if err != nil {
return err
}
Expand All @@ -73,7 +73,7 @@ var playCmd = &cobra.Command{

func playFunc(cmd *cobra.Command, args []string) (err error) {
aeCli := NewAeCli()
blockHeight, err := aeCli.APIGetHeight()
blockHeight, err := aeCli.GetHeight()
if err != nil {
return err
}
Expand Down Expand Up @@ -141,7 +141,7 @@ var ttlCmd = &cobra.Command{

func ttlFunc(cmd *cobra.Command, args []string) (err error) {
ae := NewAeCli()
height, err := ae.APIGetHeight()
height, err := ae.GetHeight()
if err != nil {
errFinal := fmt.Errorf("Error getting height from the node: %v", err)
return errFinal
Expand All @@ -160,7 +160,7 @@ var networkIDCmd = &cobra.Command{

func networkIDFunc(cmd *cobra.Command, args []string) (err error) {
ae := NewAeCli()
resp, err := ae.APIGetStatus()
resp, err := ae.GetStatus()
if err != nil {
errFinal := fmt.Errorf("Error getting status information from the node: %v", err)
return errFinal
Expand Down
14 changes: 7 additions & 7 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func inspectFunc(cmd *cobra.Command, args []string) (err error) {
}
// name
if strings.HasSuffix(object, ".aet") {
v, err := aeCli.APIGetNameEntryByName(object)
v, err := aeCli.GetNameEntryByName(object)
if err != nil {
return err
}
Expand All @@ -82,44 +82,44 @@ func inspectFunc(cmd *cobra.Command, args []string) (err error) {
switch aeternity.GetHashPrefix(object) {
case aeternity.PrefixAccountPubkey:
// account balance
v, err := aeCli.APIGetAccount(object)
v, err := aeCli.GetAccount(object)
if err != nil {
return err
}

printResult("account", v, err)

case aeternity.PrefixMicroBlockHash:
v, err := aeCli.APIGetMicroBlockHeaderByHash(object)
v, err := aeCli.GetMicroBlockHeaderByHash(object)
if err != nil {
return err
}
printResult("block", v, err)
v1, err := aeCli.APIGetMicroBlockTransactionsByHash(object)
v1, err := aeCli.GetMicroBlockTransactionsByHash(object)
if err != nil {
return err
}
printResult("transaction", v1, err)

case aeternity.PrefixKeyBlockHash:
// block
v, err := aeCli.APIGetKeyBlockByHash(object)
v, err := aeCli.GetKeyBlockByHash(object)
if err != nil {
return err
}
printResult("key-block", v, err)

case aeternity.PrefixTransactionHash:
// transaction
v, err := aeCli.APIGetTransactionByHash(object)
v, err := aeCli.GetTransactionByHash(object)
if err != nil {
return err
}
printResult("transaction", v, err)

case aeternity.PrefixOraclePubkey:
// oracle
v, err := aeCli.APIGetOracleByPubkey(object)
v, err := aeCli.GetOracleByPubkey(object)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion integration_test/aens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func getNameEntry(t *testing.T, node *aeternity.Client, name string) (responseJSON string) {
response, err := node.APIGetNameEntryByName(name)
response, err := node.GetNameEntryByName(name)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion integration_test/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestContracts(t *testing.T) {

// Confirm that contract was created
getContract := func() {
_, err = aeClient.APIGetContractByID(ctID)
_, err = aeClient.GetContractByID(ctID)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions integration_test/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestOracleWorkflow(t *testing.T) {
oraclePubKey := strings.Replace(alice.Address, "ak_", "ok_", 1)
var oracle *models.RegisteredOracle
getOracle := func() {
oracle, err = client.APIGetOracleByPubkey(oraclePubKey)
oracle, err = client.GetOracleByPubkey(oraclePubKey)
if err != nil {
t.Fatalf("APIGetOracleByPubkey: %s", err)
}
Expand All @@ -49,7 +49,7 @@ func TestOracleWorkflow(t *testing.T) {
_ = waitForTransaction(client, extendHash)

// Confirm that the oracle's TTL changed
oracle, err = client.APIGetOracleByPubkey(oraclePubKey)
oracle, err = client.GetOracleByPubkey(oraclePubKey)
if err != nil {
t.Fatalf("APIGetOracleByPubkey: %s", err)
}
Expand All @@ -71,7 +71,7 @@ func TestOracleWorkflow(t *testing.T) {

var oracleQueries *models.OracleQueries
getOracleQueries := func() {
oracleQueries, err = client.APIGetOracleQueriesByPubkey(oraclePubKey)
oracleQueries, err = client.GetOracleQueriesByPubkey(oraclePubKey)
if err != nil {
t.Fatalf("APIGetOracleQueriesByPubkey: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions integration_test/spend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestSpendTx(t *testing.T) {

// In case the recipient account already has funds, get recipient's account info. If it exists, expectedAmount = existing balance + amount + fee
expected := new(big.Int)
bobState, err := node.APIGetAccount(bob.Address)
bobState, err := node.GetAccount(bob.Address)
if err != nil {
expected.Set(amount)
} else {
Expand All @@ -46,7 +46,7 @@ func TestSpendTx(t *testing.T) {
// check the recipient's balance

getBobsAccount := func() {
bobState, err = node.APIGetAccount(bob.Address)
bobState, err = node.GetAccount(bob.Address)
if err != nil {
t.Fatalf("Couldn't get Bob's account data: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion integration_test/testsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func delay(f delayableCode) {
}

func getHeight(aeClient *aeternity.Client) (h uint64) {
h, err := aeClient.APIGetHeight()
h, err := aeClient.GetHeight()
if err != nil {
fmt.Println("Could not retrieve chain height")
return
Expand Down

0 comments on commit 6610ae8

Please sign in to comment.