Return init/migration msg with contract history

This commit is contained in:
Alex Peters 2020-07-20 17:22:10 +02:00
parent a1aa2f5e4c
commit ad520ed1d3
No known key found for this signature in database
GPG Key ID: BD28388D49EE708D
5 changed files with 42 additions and 7 deletions

36
api_migration.md Normal file
View File

@ -0,0 +1,36 @@
# Changes to the api
## [\#196](https://github.com/CosmWasm/wasmd/issues/196) - Move history of contract code migrations to their own prefix store
The `ContractDetails.initMsg` used in cosmJs was moved into a new entity `ContractCodeHistoryEntry`. They contain code updates to a contract.
### Route
This data is available via a new route `/wasm/contract/{contractAddr}/history`
### Response
A list of ContractCodeHistoryEntries with following fields:
* `operation` can be any of `"Init", "Migrate", "Genesis"`
* `code_id` uint64
* `msg` as raw json
### Errors
* 404 - for an unknown contract
### CLI
`wasmcli query wasm contract-history [bech32_address] to print all the code changes.`
Example:
`wasmcli query wasm contract-history cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c`
```json
[
{
"operation": "Init",
"code_id": 1,
"msg": "\"init-msg\""
},
{
"operation": "Migrate",
"code_id": 2,
"msg": "\"migrate-msg\""
}
]
```

View File

@ -378,13 +378,8 @@ func (k Keeper) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAd
}
func (k Keeper) appendToContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress, newEntries ...types.ContractCodeHistoryEntry) {
entries := append(k.GetContractHistory(ctx, contractAddr), newEntries...)
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.ContractHistoryStorePrefix)
var entries []types.ContractCodeHistoryEntry
bz := prefixStore.Get(contractAddr)
if bz != nil {
k.cdc.MustUnmarshalBinaryBare(bz, &entries)
}
entries = append(entries, newEntries...)
prefixStore.Set(contractAddr, k.cdc.MustMarshalBinaryBare(&entries))
}

View File

@ -240,7 +240,6 @@ func queryContractHistory(ctx sdk.Context, bech string, keeper Keeper) ([]byte,
// redact response
for i := range entries {
entries[i].Updated = nil
entries[i].Msg = nil
}
bz, err := json.MarshalIndent(entries, "", " ")

View File

@ -244,6 +244,7 @@ func TestQueryContractHistory(t *testing.T) {
expContent: []types.ContractCodeHistoryEntry{{
Operation: types.GenesisContractCodeHistoryType,
CodeID: 1,
Msg: []byte(`"init message"`),
}},
},
"response with multiple entries": {
@ -266,12 +267,15 @@ func TestQueryContractHistory(t *testing.T) {
expContent: []types.ContractCodeHistoryEntry{{
Operation: types.InitContractCodeHistoryType,
CodeID: 1,
Msg: []byte(`"init message"`),
}, {
Operation: types.MigrateContractCodeHistoryType,
CodeID: 2,
Msg: []byte(`"migrate message 1"`),
}, {
Operation: types.MigrateContractCodeHistoryType,
CodeID: 3,
Msg: []byte(`"migrate message 2"`),
}},
},
"unknown contract address": {

View File

@ -77,6 +77,7 @@ const (
var AllCodeHistoryTypes = []ContractCodeHistoryOperationType{InitContractCodeHistoryType, MigrateContractCodeHistoryType}
// ContractCodeHistoryEntry stores code updates to a contract.
type ContractCodeHistoryEntry struct {
Operation ContractCodeHistoryOperationType `json:"operation"`
CodeID uint64 `json:"code_id"`