Skip to content
Permalink
Browse files

Fix API omitempty and add support for lease (#567)

* -- Adding lease support
-- group, participation keys, etc are omitted when empty

* -- Adding lease support
-- Now Group and participation keys don't show up if empty

* make swagger happy
  • Loading branch information
rotemh authored and tsachiherman committed Nov 22, 2019
1 parent 8035498 commit 12b655021e57311e4c6c95b50b674e45c73e50af
Showing with 44 additions and 17 deletions.
  1. +24 −7 daemon/algod/api/server/v1/handlers/handlers.go
  2. +20 −10 daemon/algod/api/spec/v1/model.go
@@ -100,7 +100,15 @@ func txEncode(tx transactions.Transaction, ad transactions.ApplyData) (v1.Transa
res.FromRewards = ad.SenderRewards.Raw
res.GenesisID = tx.GenesisID
res.GenesisHash = tx.GenesisHash[:]
res.Group = tx.Group[:]

if tx.Group != (crypto.Digest{}) {
res.Group = tx.Group[:]
}

if tx.Lease != ([32]byte{}) {
res.Lease = tx.Lease[:]
}

return res, nil
}

@@ -136,6 +144,17 @@ func keyregTxEncode(tx transactions.Transaction, ad transactions.ApplyData) v1.T
}
}

func participationKeysEncode(r basics.AccountData) *v1.Participation {
var apiParticipation v1.Participation
apiParticipation.ParticipationPK = r.VoteID[:]
apiParticipation.VRFPK = r.SelectionID[:]
apiParticipation.VoteFirst = uint64(r.VoteFirstValid)
apiParticipation.VoteLast = uint64(r.VoteLastValid)
apiParticipation.VoteKeyDilution = r.VoteKeyDilution

return &apiParticipation
}

func assetParams(creator basics.Address, params basics.AssetParams) v1.AssetParams {
paramsModel := v1.AssetParams{
Total: params.Total,
@@ -566,13 +585,11 @@ func AccountInformation(ctx lib.ReqContext, w http.ResponseWriter, r *http.Reque
}
}

apiParticipation := v1.Participation{
ParticipationPK: record.VoteID[:],
VRFPK: record.SelectionID[:],
VoteFirst: uint64(record.VoteFirstValid),
VoteLast: uint64(record.VoteLastValid),
VoteKeyDilution: record.VoteKeyDilution,
var apiParticipation *v1.Participation
if record.VoteID != (crypto.OneTimeSignatureVerifier{}) {
apiParticipation = participationKeysEncode(record)
}

accountInfo := v1.Account{
Round: uint64(lastRound),
Address: addr.String(),
@@ -148,7 +148,7 @@ type Account struct {
// In future REST API versions, this field may become required.
//
// required: false
Participation Participation `json:"participation,omitempty"`
Participation *Participation `json:"participation,omitempty"`

// AssetParams specifies the parameters of assets created by this account.
//
@@ -202,26 +202,26 @@ type AssetParams struct {
// as supplied by the creator.
//
// required: false
UnitName string `json:"unitname"`
UnitName string `json:"unitname,omitempty"`

// AssetName specifies the name of this asset,
// as supplied by the creator.
//
// required: false
AssetName string `json:"assetname"`
AssetName string `json:"assetname,omitempty"`

// URL specifies a URL where more information about the asset can be
// retrieved
//
// required: false
URL string `json:"url"`
URL string `json:"url,omitempty"`

// MetadataHash specifies a commitment to some unspecified asset
// metadata. The format of this metadata is up to the application.
//
// required: false
// swagger:strfmt byte
MetadataHash []byte `json:"metadatahash"`
MetadataHash []byte `json:"metadatahash,omitempty"`

// ManagerAddr specifies the address used to manage the keys of this
// asset and to destroy it.
@@ -308,7 +308,17 @@ type Transaction struct {
//
// required: false
// swagger:strfmt byte
Note []byte `json:"noteb64"`
Note []byte `json:"noteb64,omitempty"`

// Lease enforces mutual exclusion of transactions. If this field is
// nonzero, then once the transaction is confirmed, it acquires the
// lease identified by the (Sender, Lease) pair of the transaction until
// the LastValid round passes. While this transaction possesses the
// lease, no other transaction specifying this lease can be confirmed.
//
// required: false
// swagger:strfmt byte
Lease []byte `json:"lease,omitempty"`

// ConfirmedRound indicates the block number this transaction appeared in
//
@@ -326,7 +336,7 @@ type Transaction struct {
// transaction and may attempt to commit it in the future.
//
// required: false
PoolError string `json:"poolerror"`
PoolError string `json:"poolerror,omitempty"`

// This is a list of all supported transactions.
// To add another one, create a struct with XXXTransactionType and embed it here.
@@ -378,7 +388,7 @@ type Transaction struct {
//
// required: false
// swagger:strfmt byte
Group []byte `json:"group"`
Group []byte `json:"group,omitempty"`
}

// PaymentTransactionType contains the additional fields for a payment Transaction
@@ -392,12 +402,12 @@ type PaymentTransactionType struct {
// CloseRemainderTo is the address the sender closed to
//
// required: false
CloseRemainderTo string `json:"close"`
CloseRemainderTo string `json:"close,omitempty"`

// CloseAmount is the amount sent to CloseRemainderTo, for committed transaction
//
// required: false
CloseAmount uint64 `json:"closeamount"`
CloseAmount uint64 `json:"closeamount,omitempty"`

// Amount is the amount of MicroAlgos intended to be transferred
//

0 comments on commit 12b6550

Please sign in to comment.
You can’t perform that action at this time.