Skip to content

Commit

Permalink
algod: Consolidate models (#4714)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Warehime authored Nov 14, 2022
1 parent 445b45b commit 23890a8
Show file tree
Hide file tree
Showing 51 changed files with 2,245 additions and 2,287 deletions.
4 changes: 2 additions & 2 deletions cmd/algoh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package main
import (
"context"

generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
)

// Client is a minimal interface for the RestClient
type Client interface {
Status() (generatedV2.NodeStatusResponse, error)
Status() (model.NodeStatusResponse, error)
RawBlock(round uint64) ([]byte, error)
GetGoRoutines(ctx context.Context) (string, error)
HealthCheck() error
Expand Down
14 changes: 7 additions & 7 deletions cmd/algoh/mockClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"fmt"

generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/protocol"
Expand All @@ -31,10 +31,10 @@ import (
// Helpers to initialize mockClient //
//////////////////////////////////////

func makeNodeStatuses(blocks ...uint64) (ret []generatedV2.NodeStatusResponse) {
ret = make([]generatedV2.NodeStatusResponse, 0, len(blocks))
func makeNodeStatuses(blocks ...uint64) (ret []model.NodeStatusResponse) {
ret = make([]model.NodeStatusResponse, 0, len(blocks))
for _, block := range blocks {
ret = append(ret, generatedV2.NodeStatusResponse{LastRound: block})
ret = append(ret, model.NodeStatusResponse{LastRound: block})
}
return ret
}
Expand All @@ -55,12 +55,12 @@ type mockClient struct {
GetGoRoutinesCalls int
HealthCheckCalls int
error []error
status []generatedV2.NodeStatusResponse
status []model.NodeStatusResponse
routine []string
block map[uint64]rpcs.EncodedBlockCert
}

func makeMockClient(error []error, status []generatedV2.NodeStatusResponse, block map[uint64]rpcs.EncodedBlockCert, routine []string) mockClient {
func makeMockClient(error []error, status []model.NodeStatusResponse, block map[uint64]rpcs.EncodedBlockCert, routine []string) mockClient {
return mockClient{
BlockCalls: make(map[uint64]int),
error: error,
Expand All @@ -82,7 +82,7 @@ func (c *mockClient) nextError() (e error) {
return
}

func (c *mockClient) Status() (s generatedV2.NodeStatusResponse, e error) {
func (c *mockClient) Status() (s model.NodeStatusResponse, e error) {
c.StatusCalls++
s = c.status[0]
// Repeat last status...
Expand Down
22 changes: 11 additions & 11 deletions cmd/goal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/passphrase"
generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
algodAcct "github.com/algorand/go-algorand/data/account"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/transactions"
Expand Down Expand Up @@ -528,37 +528,37 @@ var infoCmd = &cobra.Command{
},
}

func printAccountInfo(client libgoal.Client, address string, onlyShowAssetIds bool, account generatedV2.Account) bool {
var createdAssets []generatedV2.Asset
func printAccountInfo(client libgoal.Client, address string, onlyShowAssetIds bool, account model.Account) bool {
var createdAssets []model.Asset
if account.CreatedAssets != nil {
createdAssets = make([]generatedV2.Asset, len(*account.CreatedAssets))
createdAssets = make([]model.Asset, len(*account.CreatedAssets))
copy(createdAssets, *account.CreatedAssets)
sort.Slice(createdAssets, func(i, j int) bool {
return createdAssets[i].Index < createdAssets[j].Index
})
}

var heldAssets []generatedV2.AssetHolding
var heldAssets []model.AssetHolding
if account.Assets != nil {
heldAssets = make([]generatedV2.AssetHolding, len(*account.Assets))
heldAssets = make([]model.AssetHolding, len(*account.Assets))
copy(heldAssets, *account.Assets)
sort.Slice(heldAssets, func(i, j int) bool {
return heldAssets[i].AssetID < heldAssets[j].AssetID
})
}

var createdApps []generatedV2.Application
var createdApps []model.Application
if account.CreatedApps != nil {
createdApps = make([]generatedV2.Application, len(*account.CreatedApps))
createdApps = make([]model.Application, len(*account.CreatedApps))
copy(createdApps, *account.CreatedApps)
sort.Slice(createdApps, func(i, j int) bool {
return createdApps[i].Id < createdApps[j].Id
})
}

var optedInApps []generatedV2.ApplicationLocalState
var optedInApps []model.ApplicationLocalState
if account.AppsLocalState != nil {
optedInApps = make([]generatedV2.ApplicationLocalState, len(*account.AppsLocalState))
optedInApps = make([]model.ApplicationLocalState, len(*account.AppsLocalState))
copy(optedInApps, *account.AppsLocalState)
sort.Slice(optedInApps, func(i, j int) bool {
return optedInApps[i].Id < optedInApps[j].Id
Expand Down Expand Up @@ -1039,7 +1039,7 @@ func renewPartKeysInDir(dataDir string, lastValidRound uint64, fee uint64, lease
if err != nil {
return fmt.Errorf(errorRequestFail, err)
}
renewAccounts := make(map[string]generatedV2.ParticipationKey)
renewAccounts := make(map[string]model.ParticipationKey)
for _, part := range parts {
if existing, has := renewAccounts[part.Address]; has {
if existing.Key.VoteFirstValid >= part.Key.VoteLastValid {
Expand Down
4 changes: 2 additions & 2 deletions cmd/goal/accountsList.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"path/filepath"
"strings"

generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/libgoal"
)
Expand Down Expand Up @@ -204,7 +204,7 @@ func (accountList *AccountsList) loadList() {
}
}

func (accountList *AccountsList) outputAccount(addr string, acctInfo generatedV2.Account, multisigInfo *libgoal.MultisigInfo) {
func (accountList *AccountsList) outputAccount(addr string, acctInfo model.Account, multisigInfo *libgoal.MultisigInfo) {
if acctInfo.Address == "" {
fmt.Printf("[n/a]\t%s\t%s\t[n/a] microAlgos", accountList.getNameByAddress(addr), addr)
} else {
Expand Down
18 changes: 9 additions & 9 deletions cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
Expand Down Expand Up @@ -155,18 +155,18 @@ var clerkCmd = &cobra.Command{
},
}

func waitForCommit(client libgoal.Client, txid string, transactionLastValidRound uint64) (txn generatedV2.PendingTransactionResponse, err error) {
func waitForCommit(client libgoal.Client, txid string, transactionLastValidRound uint64) (txn model.PendingTransactionResponse, err error) {
// Get current round information
stat, err := client.Status()
if err != nil {
return generatedV2.PendingTransactionResponse{}, fmt.Errorf(errorRequestFail, err)
return model.PendingTransactionResponse{}, fmt.Errorf(errorRequestFail, err)
}

for {
// Check if we know about the transaction yet
txn, err = client.PendingTransactionInformation(txid)
if err != nil {
return generatedV2.PendingTransactionResponse{}, fmt.Errorf(errorRequestFail, err)
return model.PendingTransactionResponse{}, fmt.Errorf(errorRequestFail, err)
}

if txn.ConfirmedRound != nil && *txn.ConfirmedRound > 0 {
Expand All @@ -175,21 +175,21 @@ func waitForCommit(client libgoal.Client, txid string, transactionLastValidRound
}

if txn.PoolError != "" {
return generatedV2.PendingTransactionResponse{}, fmt.Errorf(txPoolError, txid, txn.PoolError)
return model.PendingTransactionResponse{}, fmt.Errorf(txPoolError, txid, txn.PoolError)
}

// check if we've already committed to the block number equals to the transaction's last valid round.
// if this is the case, the transaction would not be included in the blockchain, and we can exit right
// here.
if transactionLastValidRound > 0 && stat.LastRound >= transactionLastValidRound {
return generatedV2.PendingTransactionResponse{}, fmt.Errorf(errorTransactionExpired, txid)
return model.PendingTransactionResponse{}, fmt.Errorf(errorTransactionExpired, txid)
}

reportInfof(infoTxPending, txid, stat.LastRound)
// WaitForRound waits until round "stat.LastRound+1" is committed
stat, err = client.WaitForRound(stat.LastRound)
if err != nil {
return generatedV2.PendingTransactionResponse{}, fmt.Errorf(errorRequestFail, err)
return model.PendingTransactionResponse{}, fmt.Errorf(errorRequestFail, err)
}
}
return
Expand Down Expand Up @@ -1203,7 +1203,7 @@ var dryrunRemoteCmd = &cobra.Command{
return
}

stackToString := func(stack []generatedV2.TealValue) string {
stackToString := func(stack []model.TealValue) string {
result := make([]string, len(stack))
for i, sv := range stack {
if sv.Type == uint64(basics.TealBytesType) {
Expand All @@ -1217,7 +1217,7 @@ var dryrunRemoteCmd = &cobra.Command{
if len(resp.Txns) > 0 {
for i, txnResult := range resp.Txns {
var msgs []string
var trace []generatedV2.DryrunState
var trace []model.DryrunState
if txnResult.AppCallMessages != nil && len(*txnResult.AppCallMessages) > 0 {
msgs = *txnResult.AppCallMessages
if txnResult.AppCallTrace != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/goal/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ import (

"github.com/spf13/cobra"

generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/libgoal"
"github.com/algorand/go-algorand/network"
Expand Down Expand Up @@ -437,7 +436,7 @@ func getStatus(dataDir string) {
}
}

func makeStatusString(stat generatedV2.NodeStatusResponse) string {
func makeStatusString(stat model.NodeStatusResponse) string {
lastRoundTime := fmt.Sprintf("%.1fs", time.Duration(stat.TimeSinceLastRound).Seconds())
catchupTime := fmt.Sprintf("%.1fs", time.Duration(stat.CatchupTime).Seconds())
var statusString string
Expand Down
6 changes: 3 additions & 3 deletions cmd/loadgenerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/passphrase"
"github.com/algorand/go-algorand/daemon/algod/api/client"
generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
"github.com/algorand/go-algorand/daemon/algod/api/spec/common"
algodAcct "github.com/algorand/go-algorand/data/account"
"github.com/algorand/go-algorand/data/basics"
Expand Down Expand Up @@ -191,7 +191,7 @@ func spendLoop(cfg config, privateKey []*crypto.SignatureSecrets, publicKey []ba
return nil
}

func waitForRound(restClient client.RestClient, cfg config, spendingRound bool) (nodeStatus generatedV2.NodeStatusResponse) {
func waitForRound(restClient client.RestClient, cfg config, spendingRound bool) (nodeStatus model.NodeStatusResponse) {
var err error
for {
nodeStatus, err = restClient.Status()
Expand Down Expand Up @@ -225,7 +225,7 @@ func waitForRound(restClient client.RestClient, cfg config, spendingRound bool)

const transactionBlockSize = 800

func generateTransactions(restClient client.RestClient, cfg config, privateKeys []*crypto.SignatureSecrets, publicKeys []basics.Address, nodeStatus generatedV2.NodeStatusResponse) (queueFull bool) {
func generateTransactions(restClient client.RestClient, cfg config, privateKeys []*crypto.SignatureSecrets, publicKeys []basics.Address, nodeStatus model.NodeStatusResponse) (queueFull bool) {
start := time.Now()
var err error
var vers common.Version
Expand Down
6 changes: 3 additions & 3 deletions cmd/tealdbg/dryrunRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/algorand/go-algorand/protocol"

v2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2"
generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
)

// ddrFromParams converts serialized DryrunRequest to v2.DryrunRequest
Expand All @@ -32,7 +32,7 @@ func ddrFromParams(dp *DebugParams) (ddr v2.DryrunRequest, err error) {
return
}

var gdr generatedV2.DryrunRequest
var gdr model.DryrunRequest
err1 := protocol.DecodeJSON(dp.DdrBlob, &gdr)
if err1 == nil {
ddr, err = v2.DryrunRequestFromGenerated(&gdr)
Expand All @@ -47,7 +47,7 @@ func ddrFromParams(dp *DebugParams) (ddr v2.DryrunRequest, err error) {
return
}

func convertAccounts(accounts []generatedV2.Account) (records []basics.BalanceRecord, err error) {
func convertAccounts(accounts []model.Account) (records []basics.BalanceRecord, err error) {
for _, a := range accounts {
var addr basics.Address
addr, err = basics.UnmarshalChecksumAddress(a.Address)
Expand Down
6 changes: 3 additions & 3 deletions cmd/tealdbg/localLedger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
v2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
Expand All @@ -42,7 +42,7 @@ type AccountIndexerResponse struct {
//
// Definition:
// data/basics/userBalance.go : AccountData
Account generated.Account `json:"account"`
Account model.Account `json:"account"`

// Round at which the results were computed.
CurrentRound uint64 `json:"current-round"`
Expand All @@ -52,7 +52,7 @@ type AccountIndexerResponse struct {
type ApplicationIndexerResponse struct {

// Application index and its parameters
Application generated.Application `json:"application,omitempty"`
Application model.Application `json:"application,omitempty"`

// Round at which the results were computed.
CurrentRound uint64 `json:"current-round"`
Expand Down
23 changes: 13 additions & 10 deletions daemon/algod/api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ GOPATH := $(shell go env GOPATH)
GOPATH1 := $(firstword $(subst :, ,$(GOPATH)))

# `make all` or just `make` should be appropriate for dev work
all: server/v2/generated/types.go server/v2/generated/routes.go server/v2/generated/private/types.go server/v2/generated/private/routes.go
all: server/v2/generated/model/types.go server/v2/generated/nonparticipating/public/routes.go server/v2/generated/nonparticipating/private/routes.go server/v2/generated/participating/public/routes.go server/v2/generated/participating/private/routes.go

# `make generate` should be able to replace old `generate.sh` script and be appropriate for build system use
generate: oapi-codegen all

server/v2/generated/types.go: algod.oas3.yml
$(GOPATH1)/bin/oapi-codegen -config ./generated_types.yml algod.oas3.yml
server/v2/generated/nonparticipating/public/routes.go: algod.oas3.yml
$(GOPATH1)/bin/oapi-codegen -config ./server/v2/generated/nonparticipating/public/public_routes.yml algod.oas3.yml

server/v2/generated/routes.go: algod.oas3.yml
$(GOPATH1)/bin/oapi-codegen -config ./generated_server.yml algod.oas3.yml
server/v2/generated/nonparticipating/private/routes.go: algod.oas3.yml
$(GOPATH1)/bin/oapi-codegen -config ./server/v2/generated/nonparticipating/private/private_routes.yml algod.oas3.yml

server/v2/generated/private/types.go: algod.oas3.yml
$(GOPATH1)/bin/oapi-codegen -config ./private_types.yml algod.oas3.yml
server/v2/generated/participating/public/routes.go: algod.oas3.yml
$(GOPATH1)/bin/oapi-codegen -config ./server/v2/generated/participating/public/public_routes.yml algod.oas3.yml

server/v2/generated/private/routes.go: algod.oas3.yml
$(GOPATH1)/bin/oapi-codegen -config ./private_server.yml algod.oas3.yml
server/v2/generated/participating/private/routes.go: algod.oas3.yml
$(GOPATH1)/bin/oapi-codegen -config ./server/v2/generated/participating/private/private_routes.yml algod.oas3.yml

server/v2/generated/model/types.go: algod.oas3.yml
$(GOPATH1)/bin/oapi-codegen -config ./server/v2/generated/model/model_types.yml algod.oas3.yml

algod.oas3.yml: algod.oas2.json
curl -s -X POST "https://converter.swagger.io/api/convert" -H "accept: application/json" -H "Content-Type: application/json" -d @./algod.oas2.json -o .3tmp.json
Expand All @@ -28,6 +31,6 @@ oapi-codegen: .PHONY
../../../scripts/buildtools/install_buildtools.sh -o github.com/algorand/oapi-codegen -c github.com/algorand/oapi-codegen/cmd/oapi-codegen

clean:
rm -rf server/v2/generated/types.go server/v2/generated/routes.go server/v2/generated/private/types.go server/v2/generated/private/routes.go algod.oas3.yml
rm -rf server/v2/generated/model/types.go server/v2/generated/nonparticipating/public/routes.go server/v2/generated/nonparticipating/private/routes.go server/v2/generated/participating/public/routes.go server/v2/generated/participating/private/routes.go algod.oas3.yml

.PHONY:
Loading

0 comments on commit 23890a8

Please sign in to comment.