algorand / algorand/go-algorand
REST v2 Codegeneration: Avoid Re-defining Types in /blocks and /transactions
- Ngôn ngữ chính
- Go
- Star
- 1.4k
- Fork
- 537
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 17
Mô tả
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`
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.