mirror of https://github.com/certusone/wasmd.git
Return init/migration msg with contract history
This commit is contained in:
parent
a1aa2f5e4c
commit
ad520ed1d3
|
@ -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\""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
|
@ -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) {
|
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)
|
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))
|
prefixStore.Set(contractAddr, k.cdc.MustMarshalBinaryBare(&entries))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,7 +240,6 @@ func queryContractHistory(ctx sdk.Context, bech string, keeper Keeper) ([]byte,
|
||||||
// redact response
|
// redact response
|
||||||
for i := range entries {
|
for i := range entries {
|
||||||
entries[i].Updated = nil
|
entries[i].Updated = nil
|
||||||
entries[i].Msg = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := json.MarshalIndent(entries, "", " ")
|
bz, err := json.MarshalIndent(entries, "", " ")
|
||||||
|
|
|
@ -244,6 +244,7 @@ func TestQueryContractHistory(t *testing.T) {
|
||||||
expContent: []types.ContractCodeHistoryEntry{{
|
expContent: []types.ContractCodeHistoryEntry{{
|
||||||
Operation: types.GenesisContractCodeHistoryType,
|
Operation: types.GenesisContractCodeHistoryType,
|
||||||
CodeID: 1,
|
CodeID: 1,
|
||||||
|
Msg: []byte(`"init message"`),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
"response with multiple entries": {
|
"response with multiple entries": {
|
||||||
|
@ -266,12 +267,15 @@ func TestQueryContractHistory(t *testing.T) {
|
||||||
expContent: []types.ContractCodeHistoryEntry{{
|
expContent: []types.ContractCodeHistoryEntry{{
|
||||||
Operation: types.InitContractCodeHistoryType,
|
Operation: types.InitContractCodeHistoryType,
|
||||||
CodeID: 1,
|
CodeID: 1,
|
||||||
|
Msg: []byte(`"init message"`),
|
||||||
}, {
|
}, {
|
||||||
Operation: types.MigrateContractCodeHistoryType,
|
Operation: types.MigrateContractCodeHistoryType,
|
||||||
CodeID: 2,
|
CodeID: 2,
|
||||||
|
Msg: []byte(`"migrate message 1"`),
|
||||||
}, {
|
}, {
|
||||||
Operation: types.MigrateContractCodeHistoryType,
|
Operation: types.MigrateContractCodeHistoryType,
|
||||||
CodeID: 3,
|
CodeID: 3,
|
||||||
|
Msg: []byte(`"migrate message 2"`),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
"unknown contract address": {
|
"unknown contract address": {
|
||||||
|
|
|
@ -77,6 +77,7 @@ const (
|
||||||
|
|
||||||
var AllCodeHistoryTypes = []ContractCodeHistoryOperationType{InitContractCodeHistoryType, MigrateContractCodeHistoryType}
|
var AllCodeHistoryTypes = []ContractCodeHistoryOperationType{InitContractCodeHistoryType, MigrateContractCodeHistoryType}
|
||||||
|
|
||||||
|
// ContractCodeHistoryEntry stores code updates to a contract.
|
||||||
type ContractCodeHistoryEntry struct {
|
type ContractCodeHistoryEntry struct {
|
||||||
Operation ContractCodeHistoryOperationType `json:"operation"`
|
Operation ContractCodeHistoryOperationType `json:"operation"`
|
||||||
CodeID uint64 `json:"code_id"`
|
CodeID uint64 `json:"code_id"`
|
||||||
|
|
Loading…
Reference in New Issue