Skip to content

Commit

Permalink
genericify things
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Aug 13, 2023
1 parent 02f4f2d commit 9ccb6af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
6 changes: 3 additions & 3 deletions daemon/algod/api/server/v2/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ func AssetParamsToAsset(creator string, idx basics.AssetIndex, params *basics.As
Decimals: uint64(params.Decimals),
DefaultFrozen: &frozen,
Name: omitEmpty(printableUTF8OrEmpty(params.AssetName)),
NameB64: byteOrNil([]byte(params.AssetName)),
NameB64: sliceOrNil([]byte(params.AssetName)),
UnitName: omitEmpty(printableUTF8OrEmpty(params.UnitName)),
UnitNameB64: byteOrNil([]byte(params.UnitName)),
UnitNameB64: sliceOrNil([]byte(params.UnitName)),
Url: omitEmpty(printableUTF8OrEmpty(params.URL)),
UrlB64: byteOrNil([]byte(params.URL)),
UrlB64: sliceOrNil([]byte(params.URL)),
Clawback: addrOrNil(params.Clawback),
Freeze: addrOrNil(params.Freeze),
Manager: addrOrNil(params.Manager),
Expand Down
2 changes: 1 addition & 1 deletion daemon/algod/api/server/v2/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ func (v2 *Handlers) GetApplicationBoxes(ctx echo.Context, applicationID uint64,
lastRound := ledger.Latest()
keyPrefix := apps.MakeBoxKey(uint64(appIdx), "")

requestedMax, algodMax := nilToZero(params.Max), v2.Node.Config().MaxAPIBoxPerApplication
requestedMax, algodMax := nilToDefault(params.Max), v2.Node.Config().MaxAPIBoxPerApplication

Check warning on line 1496 in daemon/algod/api/server/v2/handlers.go

View check run for this annotation

Codecov / codecov/patch

daemon/algod/api/server/v2/handlers.go#L1496

Added line #L1496 was not covered by tests
max := applicationBoxesMaxKeys(requestedMax, algodMax)

if max != math.MaxUint64 {
Expand Down
18 changes: 6 additions & 12 deletions daemon/algod/api/server/v2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,12 @@ func omitEmpty[T comparable](val T) *T {
return &val
}

func byteOrNil(data []byte) *[]byte {
if len(data) == 0 {
return nil
}
return &data
}

func nilToZero(numPtr *uint64) uint64 {
if numPtr == nil {
return 0
func nilToDefault[T any](valPtr *T) T {
if valPtr == nil {
var defaultV T
return defaultV

Check warning on line 116 in daemon/algod/api/server/v2/utils.go

View check run for this annotation

Codecov / codecov/patch

daemon/algod/api/server/v2/utils.go#L113-L116

Added lines #L113 - L116 were not covered by tests
}
return *numPtr
return *valPtr

Check warning on line 118 in daemon/algod/api/server/v2/utils.go

View check run for this annotation

Codecov / codecov/patch

daemon/algod/api/server/v2/utils.go#L118

Added line #L118 was not covered by tests
}

func computeCreatableIndexInPayset(tx node.TxnWithStatus, txnCounter uint64, payset []transactions.SignedTxnWithAD) (cidx *uint64) {
Expand Down Expand Up @@ -376,7 +370,7 @@ func convertTealValue(tv basics.TealValue) model.AvmValue {
return model.AvmValue{
Type: uint64(tv.Type),
Uint: omitEmpty(tv.Uint),
Bytes: byteOrNil([]byte(tv.Bytes)),
Bytes: sliceOrNil([]byte(tv.Bytes)),

Check warning on line 373 in daemon/algod/api/server/v2/utils.go

View check run for this annotation

Codecov / codecov/patch

daemon/algod/api/server/v2/utils.go#L369-L373

Added lines #L369 - L373 were not covered by tests
}
}

Expand Down

0 comments on commit 9ccb6af

Please sign in to comment.