Skip to content

Commit

Permalink
feat: add missing contract states
Browse files Browse the repository at this point in the history
Signed-off-by: jonathansumner <jonathansumner98@gmail.com>
  • Loading branch information
Jonathansumner committed Jun 27, 2024
1 parent 0cf5346 commit 7ea7c55
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion app/upgrade_0_11_4.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/binary"
"encoding/csv"
"encoding/hex"
"encoding/json"
"fmt"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
Expand All @@ -20,7 +21,12 @@ var reconciliationData []byte
//go:embed reconciliation_data_testnet.csv
var reconciliationDataTestnet []byte

var reconciliationBalancesKey = prefixStringWithLength("balances")
var (
reconciliationTotalBalanceKey = []byte("total_balance")
reconciliationNOutstandingAddressesKey = []byte("n_outstanding_addresses")
reconciliationStateKey = []byte("state")
reconciliationBalancesKey = prefixStringWithLength("balances")
)

func getStringPtr(val string) *string {
return &val
Expand Down Expand Up @@ -202,6 +208,25 @@ func (app *App) ReplaceReconciliationContractState(ctx types.Context, networkInf
prefixStore.Set(key, value)
}

totalBalanceRecord, err := contractState.AggregatedBalancesAmount.MarshalJSON()
if err != nil {
return err
}

stateRecord := ReconciliationContractStateRecord{
Paused: true,
}

var stateRecordJsonBz []byte
stateRecordJsonBz, err = json.Marshal(stateRecord)
if err != nil {
return err
}

prefixStore.Set(reconciliationTotalBalanceKey, totalBalanceRecord)
prefixStore.Set(reconciliationNOutstandingAddressesKey, []byte(fmt.Sprintf("%d", contractState.NumberOfBalanceRecords)))
prefixStore.Set(reconciliationStateKey, stateRecordJsonBz)

if contractState.NumberOfBalanceRecords != len(contractState.Balances) {
return fmt.Errorf("manifest: ContractState: number of elements in the `Balances` array does not match the `NumberOfBalanceRecords`")
}
Expand Down Expand Up @@ -384,3 +409,7 @@ func (app *App) getContractData(ctx types.Context, contractAddr string) (*types.

return &addr, &store, &prefixStore, nil
}

type ReconciliationContractStateRecord struct {
Paused bool `json:"paused"`
}

0 comments on commit 7ea7c55

Please sign in to comment.