algorand / algorand/go-algorand

REST v2 Codegeneration: Avoid Re-defining Types in /blocks and /transactions

Ouverte
#1,015 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Team Carbon-11 Team Lamprey tech debt
Langage dominant
Go
Étoiles
1.4k
Forks
537
Merge moyen
1 j 7 h
PR mergées (30 j)
18

Description

The generated code defines `Block` and `SignedTransaction` as a generic structure specified by `map[string]interface{}`. In the spec this is just a JSON `object`. The generated type was intended to express "map of objects" and was intentionally under-specifying so that we don't need to synchronize the backend type and the specification. Rather the REST API will always return the backend representation of these objects.

I was able to get a `map[string]interface{}` by serializeing and deserializing as the `map[string]interface{}` type. There was some trouble getting the generic type working with `json/encoder`, at the time I didn't realize we also use `go-codec` for JSON, so maybe that one would work. For now there are 3 spots which redefine the types inline:
```
response := struct {
AssetIndex *uint64 `codec:"asset-index,omitempty"`
CloseRewards *uint64 `codec:"close-rewards,omitempty"`
ClosingAmount *uint64 `codec:"closing-amount,omitempty"`
ConfirmedRound *uint64 `codec:"confirmed-round,omitempty"`
PoolError string `codec:"pool-error"`
ReceiverRewards *uint64 `codec:"receiver-rewards,omitempty"`
SenderRewards *uint64 `codec:"sender-rewards,omitempty"`
--> Txn transactions.SignedTxn `codec:"txn"`
}
```

To avoid this we could explore the following:
1) expand the oapi-codegen type-mapping so that we can specify an existing type + import it in the generated code.
2) See if the serialize/deserialize/serialize trick works using `go-codec` instead of `json/encoder`

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.