Skip to content

Commit

Permalink
prefer nil instead of empty byte array for easier comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos committed Jun 22, 2023
1 parent c9416f2 commit 160a0e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions daemon/algod/api/server/v2/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,18 @@ func convertTKVToGenerated(tkv *basics.TealKeyValue) *model.TealKeyValueStore {

converted := make(model.TealKeyValueStore, 0, len(*tkv))
for k, v := range *tkv {
converted = append(converted, model.TealKeyValue{
convertedKv := model.TealKeyValue{
Key: []byte(k),
Value: model.TealValue{
Type: uint64(v.Type),
Bytes: []byte(v.Bytes),
Uint: v.Uint,
},
})
}
if len(convertedKv.Value.Bytes) == 0 {
convertedKv.Value.Bytes = nil
}
converted = append(converted, convertedKv)
}
sort.Slice(converted, func(i, j int) bool {
return bytes.Compare(converted[i].Key, converted[j].Key) < 0
Expand Down
6 changes: 3 additions & 3 deletions daemon/algod/api/server/v2/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ func TestAccount(t *testing.T) {

makeTKV := func(k string, v interface{}) model.TealKeyValue {
value := model.TealValue{}
switch v.(type) {
switch vKnown := v.(type) {
case int:
value.Uint = uint64(v.(int))
value.Uint = uint64(vKnown)
value.Type = uint64(basics.TealUintType)
case string:
value.Bytes = []byte(v.(string))
value.Bytes = []byte(vKnown)
value.Type = uint64(basics.TealBytesType)
default:
panic(fmt.Sprintf("Unknown teal type %v", t))
Expand Down

0 comments on commit 160a0e5

Please sign in to comment.