diff --git a/scripts/custo/meter/a_meter_billing.go b/scripts/custo/meter/a_meter_billing.go index 36ffd5d8..25e31f0e 100644 --- a/scripts/custo/meter/a_meter_billing.go +++ b/scripts/custo/meter/a_meter_billing.go @@ -96,28 +96,34 @@ func setProducerbillingline(lineid uint64, cycleid uint64, lineWh uint64, lineWh // Get Meter Readings from the blockchain // Follow only once the chain to reduce load func (k Keeper) loadMeterReadingValues(ctx sdk.Context, cycleID uint64)(map[string]meterReading, map[string]meterReading, map[string]meterReading, map[string]meterReading, error) { + // Performance Management + start := time.Now() // Local Variables var previousConsumerMap map[string]meterReading = make(map[string]meterReading) var previousProducerMap map[string]meterReading = make(map[string]meterReading) var currentConsumerMap map[string]meterReading = make(map[string]meterReading) var currentProducerMap map[string]meterReading = make(map[string]meterReading) + var i int = 0 // Find the cycle start and end timestamps theCycle, _ := k.GetBillingcycles(ctx, cycleID) currenttimebegin := theCycle.Begin currenttimeend := theCycle.End + comment := fmt.Sprintf("# BEGIN loadMeterReadingValues cycleID:%d Timebegin:%d Timeend:%d ###################################", cycleID, currenttimebegin, currenttimeend) store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MeterreadingsKeyPrefix)) iterator := sdk.KVStorePrefixIterator(store, []byte{}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var val types.Meterreadings // The original format on the block chain var mrInn meterReading = currentConsumerMap[val.DeviceID] // To save memory usage we use this type that is far more compact - var mrOUT meterReading = currentProducerMap[val.DeviceID] // To save memory usage we use this type that is far more compact + var mrOUT meterReading = currentProducerMap[val.DeviceID] // To save memory usage we use this type that is far more compact + i++ k.cdc.MustUnmarshal(iterator.Value(), &val) + comment += fmt.Sprintf("\n\t#%d %s val.Timestamp:%d previous:%t current:%t future:%t ",i,resolvName(val.DeviceID),val.Timestamp,(val.Timestamp < currenttimebegin), ((val.Timestamp >= currenttimebegin) && (val.Timestamp <= currenttimeend)),(val.Timestamp > currenttimeend)) if ((val.Timestamp < currenttimebegin)) { // More safe than ((val.Timestamp <= prevtimeend)) switch val.Phase { case 1: { // Previous Cycles - if (mrInn.whphase1 < val.Whin) { mrInn.whphase1 = val.Whin ; previousConsumerMap[val.DeviceID] = mrInn } // values can come in disorder so we upgrade only if it is bigger - if (mrOUT.whphase1 < val.Whout) { mrOUT.whphase1 = val.Whout ; previousProducerMap[val.DeviceID] = mrOUT } // values can come in disorder so we upgrade only if it is bigger + if (mrInn.whphase1 < val.Whin) { mrInn.whphase1 = val.Whin ; previousConsumerMap[val.DeviceID] = mrInn; comment += fmt.Sprintf(" previous Consum ") } // values can come in disorder so we upgrade only if it is bigger + if (mrOUT.whphase1 < val.Whout) { mrOUT.whphase1 = val.Whout ; previousProducerMap[val.DeviceID] = mrOUT; comment += fmt.Sprintf(" previous Produc ") } // values can come in disorder so we upgrade only if it is bigger } case 2: { if (mrInn.whphase2 < val.Whin) { mrInn.whphase2 = val.Whin ; previousConsumerMap[val.DeviceID] = mrInn } // values can come in disorder so we upgrade only if it is bigger @@ -132,8 +138,8 @@ func (k Keeper) loadMeterReadingValues(ctx sdk.Context, cycleID uint64)(map[stri if ((val.Timestamp >= currenttimebegin) && (val.Timestamp <= currenttimeend)) { switch val.Phase { case 1: { // Current Cycles - if (mrInn.whphase1 < val.Whin) { mrInn.whphase1 = val.Whin ; currentConsumerMap[val.DeviceID] = mrInn } // values can come in disorder so we upgrade only if it is bigger - if (mrOUT.whphase1 < val.Whout) { mrOUT.whphase1 = val.Whout ; currentProducerMap[val.DeviceID] = mrOUT } // values can come in disorder so we upgrade only if it is bigger + if (mrInn.whphase1 < val.Whin) { mrInn.whphase1 = val.Whin ; currentConsumerMap[val.DeviceID] = mrInn; comment += fmt.Sprintf(" current Consum ") } // values can come in disorder so we upgrade only if it is bigger + if (mrOUT.whphase1 < val.Whout) { mrOUT.whphase1 = val.Whout ; currentProducerMap[val.DeviceID] = mrOUT; comment += fmt.Sprintf(" current Produc ") } // values can come in disorder so we upgrade only if it is bigger } case 2: { if (mrInn.whphase2 < val.Whin) { mrInn.whphase2 = val.Whin ; currentConsumerMap[val.DeviceID] = mrInn } // values can come in disorder so we upgrade only if it is bigger @@ -147,6 +153,11 @@ func (k Keeper) loadMeterReadingValues(ctx sdk.Context, cycleID uint64)(map[stri } } } + comment += fmt.Sprintf("\n\npreviousConsumerMap:%+v\n\npreviousProducerMap:%+v\n\ncurrentConsumerMap:%+v\n\ncurrentProducerMap:%+v\n",previousConsumerMap, previousProducerMap, currentConsumerMap, currentProducerMap) + // Performance Management + elapsed := time.Since(start) + comment += fmt.Sprintf("\n# END # loadMeterReadingValues took %s @ %s #############################\n", elapsed,time.Now()) + writelog(comment) return previousConsumerMap, previousProducerMap, currentConsumerMap, currentProducerMap, nil } @@ -400,7 +411,7 @@ func makePrepareBill(ppcMap map[string]types.PowerPurchaseContract,ppaMap map[st // CycleID definitions PreviousCycleID := cycleID PreviousCycleID-- // Decrement the current cycle ID to get the previous - comment = fmt.Sprintf("CycleID: %d Previous CycleID: %d\n", cycleID, PreviousCycleID) + comment = fmt.Sprintf("# makePrepareBill # CycleID: %d Previous CycleID: %d\n", cycleID, PreviousCycleID) comment += "=== addCurrentProduction =============================================\n" ppcMap = addCurrentProduction(ppcMap, currentCycleProduceOutMap, previousCycleProduceOutMap) @@ -413,7 +424,7 @@ for customerDeviceID, _ := range currentCycleConsumeInMap { // makePrepareBill thisCustomerBill.BillDate = uint64(time.Now().Unix()) thisCustomerBill.CustomerDeviceID = customerDeviceID thisCustomerBill.Paid = false - var consumed meterReading // Get the amount of WH consumed & Set the WH consumed value per phase + var consumed meterReading // Get the amount of WH consumed & Set the WH consumed value per phase consumed.whphase1 = currentCycleConsumeInMap[customerDeviceID].whphase1 - previousCycleConsumeInMap[customerDeviceID].whphase1 consumed.whphase2 = currentCycleConsumeInMap[customerDeviceID].whphase2 - previousCycleConsumeInMap[customerDeviceID].whphase2 consumed.whphase3 = currentCycleConsumeInMap[customerDeviceID].whphase3 - previousCycleConsumeInMap[customerDeviceID].whphase3 @@ -478,36 +489,132 @@ for customerDeviceID, _ := range currentCycleConsumeInMap { // makePrepareBill } } } - comment += "### Output customerbill ###################\n" - jsonStr, _ := json.MarshalIndent(customerbill, "", " ") - comment += fmt.Sprintf("%+s\n",jsonStr) - comment += "### Output customerBillLines ###################\n" - jsonStr, _ = json.MarshalIndent(customerBillLines, "", " ") - comment += fmt.Sprintf("%+s\n",jsonStr) - comment += "### Output producerBillLines ###################\n" - jsonStr, _ = json.MarshalIndent(producerBillLines, "", " ") - comment += fmt.Sprintf("%+s\n",jsonStr) - elapsed := time.Since(start) - comment += fmt.Sprintf("### END ### makePrepareBill Cycle:%d took %s @ %s\n", cycleID, elapsed,time.Now()) + comment += "### Output customerbill ###################\n" + jsonStr, _ := json.MarshalIndent(customerbill, "", " ") + comment += fmt.Sprintf("%+s\n",jsonStr) + comment += "### Output customerBillLines ###################\n" + jsonStr, _ = json.MarshalIndent(customerBillLines, "", " ") + comment += fmt.Sprintf("%+s\n",jsonStr) + comment += "### Output producerBillLines ###################\n" + jsonStr, _ = json.MarshalIndent(producerBillLines, "", " ") + comment += fmt.Sprintf("%+s\n",jsonStr) + elapsed := time.Since(start) + comment += fmt.Sprintf("### END ### makePrepareBill Cycle:%d took %s @ %s\n", cycleID, elapsed,time.Now()) writelog(comment) return customerbill, customerBillLines, producerBillLines, comment, err } -func (k msgServer) recordAllPreparedBills(goCtx context.Context, customerBill map[string]types.Customerbills, customerBillingLines []types.Customerbillingline, producerBillingLines []types.Producerbillingline)( string, error){ +func (k msgServer) recordAllPreparedBills(goCtx context.Context, customerBill map[string]types.Customerbills, customerBillingLines []types.Customerbillingline, producerBillingLines []types.Producerbillingline, executePayment bool)( string, error){ // Performance Management - start := time.Now() + start := time.Now() + ctx := sdk.UnwrapSDKContext(goCtx) comment := "### START ### recordAllPreparedBills ########################\n" - // TO DO + //////// customer Bill ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + for _, cbill := range customerBill{ + // Check if the value already exists + _, isFound := k.GetCustomerbills( + ctx, + cbill.BillCycleID, + cbill.CustomerDeviceID, + ) + if isFound { + errmsg := fmt.Sprintf("# recordAllPreparedBills # Error: index already set Cycle:%d Customer:%s\n", cbill.BillCycleID, cbill.CustomerDeviceID ) + comment += errmsg + } else { + if (cbill.BillTotalPrice>0) { + // set the specific customerbilling in the store from its index + k.SetCustomerbills( + ctx, + cbill, + ) + comment += fmt.Sprintf("# recordAllPreparedBills # OK customer Bill REGISTERED Cycle:%d Total:%d %s Customer:%s\n", cbill.BillCycleID, cbill.BillTotalPrice, cbill.BillCurrency, resolvName(cbill.CustomerDeviceID) ) + } else { + comment += fmt.Sprintf("# recordAllPreparedBills # WARNING cannot register when price =0 Cycle:%d Total:%d %s Customer:%s\n", cbill.BillCycleID, cbill.BillTotalPrice, cbill.BillCurrency, resolvName(cbill.CustomerDeviceID)) + } + } + } + //////// customer billing line ///////////////////////////////////////////////////////////////////////////////////////////////////// + for _, cbill := range customerBillingLines{ + // Check if the value already exists + _, isFound := k.GetCustomerbillingline( + ctx, + cbill.CustomerDeviceID, + cbill.CycleID, + cbill.Lineid, + ) + if isFound { + errmsg := fmt.Sprintf("# recordAllPreparedBills # Error: index already set Line:%d Cycle:%d Customer:%s\n", cbill.Lineid, cbill.CycleID, resolvName(cbill.CustomerDeviceID)) + comment += errmsg + // sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, errmsg) + } else { + if (cbill.LineWhTotalPrice>0) { + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Proceed to the payment + // Note: This module uses the SendCoins function of bankKeeper so Add SendCoins to x/meter/types/expected_keepers.go + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + if (executePayment == true ) { + customer, _ := sdk.AccAddressFromBech32(cbill.CustomerDeviceID) + producer, _ := sdk.AccAddressFromBech32(cbill.ProducerDeviceID) + amount, err := sdk.ParseCoinsNormalized(string(cbill.LineWhTotalPrice) + cbill.Curency) + if err != nil { + errmsg := "Cannot parse coins in invoice amount" + comment += errmsg + //return nil, sdkerrors.Wrap(types.ErrWrongLoanState, errmsg) + } + // send tokens from the customer to the producer + err = k.bankKeeper.SendCoins(ctx, customer, producer, amount) + if err != nil { + errmsg := "Sendcoin failed to send coins" + comment += errmsg + //return nil, sdkerrors.Wrap(types.ErrWrongLoanState, "Cannot parse coins in loan amount") + } else { + // Update the bill with the payment result + // cbill.Paid = true + } + } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // END payment + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // set the specific billingline in the store from its index + k.SetCustomerbillingline( + ctx, + cbill, + ) + comment += fmt.Sprintf("# recordAllPreparedBills # OK Customer billing line REGISTERED Cycle:%d Line:%d Phase:%d Total:%d %s Customer:%s\n", cbill.CycleID, cbill.Lineid, cbill.Phase, cbill.LineWhTotalPrice, cbill.Curency, resolvName(cbill.CustomerDeviceID)) + } else { + comment += fmt.Sprintf("# recordAllPreparedBills # WARNING price =0 Cycle:%d Line:%d Phase:%d Total:%d %s Customer:%s\n", cbill.CycleID, cbill.Lineid, cbill.Phase, cbill.LineWhTotalPrice, cbill.Curency, resolvName(cbill.CustomerDeviceID)) + } + } + } + //////// producer billing line ///////////////////////////////////////////////////////////////////////////////////////////////////// + for _, cbill := range producerBillingLines{ + // Check if the value already exists + _, isFound := k.GetCustomerbillingline( + ctx, + cbill.ProducerDeviceID, + cbill.CycleID, + cbill.Lineid, + ) + if isFound { + errmsg := fmt.Sprintf("# recordAllPreparedBills # Error: index already set Line:%d Cycle:%d Producer:%s\n", cbill.Lineid, cbill.CycleID, resolvName(cbill.ProducerDeviceID)) + comment += errmsg + // sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, errmsg) + } else { + if (cbill.LineWhTotalPrice>0) { + // set the specific customerbillingline in the store from its index + k.SetProducerbillingline( + ctx, + cbill, + ) + comment += fmt.Sprintf("# recordAllPreparedBills # OK Producer billing line REGISTERED Cycle:%d Line:%d Phase:%d Total:%d %s Producer:%s Customer:%s\n", cbill.CycleID, cbill.Lineid, cbill.Phase, cbill.LineWhTotalPrice, cbill.Curency, resolvName(cbill.ProducerDeviceID), resolvName(cbill.CustomerDeviceID)) + } else { + comment += fmt.Sprintf("# recordAllPreparedBills # WARNING price =0 Cycle:%d Line:%d Phase:%d Total:%d Producer:%s %s Customer:%s\n", cbill.CycleID, cbill.Lineid, cbill.Phase, cbill.LineWhTotalPrice, cbill.Curency, resolvName(cbill.ProducerDeviceID), resolvName(cbill.CustomerDeviceID)) + } + } + } + + // TO DO: save the bill in Json - jsonBill1, err := json.Marshal(customerBillingLines) - if err != nil { - fmt.Printf("Error: %s", err.Error()) - } - jsonBill2, err := json.Marshal(producerBillingLines) - if err != nil { - fmt.Printf("Error: %s", err.Error()) - } - fmt.Printf(" customerbillinglines JSon:%s \n producerbillinglines JSon:%s\n",string(jsonBill1),string(jsonBill2)) elapsed := time.Since(start) comment += fmt.Sprintf("### END ### recordAllPreparedBills took %s @ %s ###############\n", elapsed,time.Now()) writelog(comment) diff --git a/scripts/custo/meter/expected_keepers.go b/scripts/custo/meter/expected_keepers.go new file mode 100644 index 00000000..06c28642 --- /dev/null +++ b/scripts/custo/meter/expected_keepers.go @@ -0,0 +1,19 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + // Methods imported from bank should be defined here +} diff --git a/scripts/custo/meter/msg_server_prepare_bill.go b/scripts/custo/meter/msg_server_prepare_bill.go index ce3aab6d..7efc641a 100644 --- a/scripts/custo/meter/msg_server_prepare_bill.go +++ b/scripts/custo/meter/msg_server_prepare_bill.go @@ -20,6 +20,7 @@ func (k msgServer) PrepareBill(goCtx context.Context, msg *types.MsgPrepareBill) start := time.Now() // Variables ctx := sdk.UnwrapSDKContext(goCtx) + var executePayment = true // var executePayment = msg.ExecutePayment var comment string = "" var ppcList []types.PowerPurchaseContract = k.GetAllPowerPurchaseContract(ctx) // from x/meter/keeper/power_purchase_contract.go var ppaList []types.PpaMap = k.GetAllPpaMap(ctx) // from x/meter/keeper/ppa_map.go GetAllPpaMap returns all ppaMap func (k Keeper) GetAllPpaMap(ctx sdk.Context) (list []types.PpaMap) @@ -28,16 +29,19 @@ func (k msgServer) PrepareBill(goCtx context.Context, msg *types.MsgPrepareBill) comment += fmt.Sprintf("\n### BEGIN ### PrepareBill ### ppcList: %+v\n======\nppaMap: %+v\n======\n", ppcList, ppaMap) // Load values previousCycleConsumeInMap, previousCycleProduceOutMap, currentCycleConsumeInMap, currentCycleProduceOutMap, _ := k.loadMeterReadingValues(ctx, msg.CycleID) + comment += fmt.Sprintf("\n### PrepareBill ###\npreviousCycleConsumeInMap:%+v\npreviousCycleProduceOutMap:%+v\ncurrentCycleConsumeInMap:%+v\ncurrentCycleProduceOutMap:%+v\n",previousCycleConsumeInMap, previousCycleProduceOutMap, currentCycleConsumeInMap, currentCycleProduceOutMap) + writelog(comment) // Prepare the bills customerbill, customerbillinglines, producerbillinglines, commentPrepare, err := makePrepareBill(ppcMap, ppaMap, msg.CycleID, previousCycleConsumeInMap, previousCycleProduceOutMap, currentCycleConsumeInMap, currentCycleProduceOutMap) if (msg.Record == true) { // Record the bill on the chain - commentRecord, _ := k.recordAllPreparedBills(goCtx, customerbill, customerbillinglines, producerbillinglines) + commentRecord, _ := k.recordAllPreparedBills(goCtx, customerbill, customerbillinglines, producerbillinglines, executePayment) comment += commentRecord } - + comment += fmt.Sprintf("\n### PrepareBill ###\ncustomerbill:%+v\ncustomerbillinglines:%+v\nproducerbillinglines:%+v\n",customerbill, customerbillinglines, producerbillinglines, commentPrepare) elapsed := time.Since(start) comment += fmt.Sprintf("\n### END ### PrepareBill All took %s @ %s ###\n", elapsed,time.Now()) fmt.Printf(comment) + writelog(comment) return &types.MsgPrepareBillResponse{JsonCustomerbill: "",JsonProducerbill: commentPrepare, Comment: comment}, err } \ No newline at end of file diff --git a/scripts/scaffold_ALL_electra_script.sh b/scripts/scaffold_ALL_electra_script.sh index b5734ca9..bdee1733 100644 --- a/scripts/scaffold_ALL_electra_script.sh +++ b/scripts/scaffold_ALL_electra_script.sh @@ -66,7 +66,7 @@ ignite scaffold query currentcycleID --response cycleID:uint,begin:uint,end:uint ################################################################################################################## ignite scaffold message prepareBill cycleID:uint record:bool executePayment:bool --response jsonCustomerbill:string,jsonProducerbill:string,comment:string --module meter --desc "Increment the current cycleID:uint" -y -ignite scaffold map customerbillingline producerDeviceID:string billContractID:string lineWh:uint lineWhPrice:uint curency:string lineWhTotalPrice:uint phase:uint --index customerDeviceID:string,cycleID:uint,lineid:uint --module meter -y +ignite scaffold map customerbillingline producerDeviceID:string billContractID:string lineWh:uint lineWhPrice:uint curency:string lineWhTotalPrice:uint phase:uint --index customerDeviceID:string,cycleID:uint,lineid:uint,paid:bool --module meter -y # Display the content of one customer bill ## ## @@ -76,7 +76,7 @@ ignite scaffold map customerbills billDate:uint billTotalWh:uint billTotalPrice: # Select the customer bills Beteween a start and end timestamps #ignite scaffold query listcustomerbills customerDeviceID:string start:uint end:uint billCycleID:uint paid:bool --response listofbills,total:uint --module meter --desc "List the customer bills from START to END [parameters are interpreted as unix DateTime timestams]" -y # -ignite scaffold map producerbillingline customerDeviceID:string billContractID:string lineWh:uint lineWhPrice:uint curency:string lineWhTotalPrice:uint phase:uint --index producerDeviceID:string,cycleID:uint,lineid:uint --module meter -y +ignite scaffold map producerbillingline customerDeviceID:string billContractID:string lineWh:uint lineWhPrice:uint curency:string lineWhTotalPrice:uint phase:uint --index producerDeviceID:string,cycleID:uint,lineid:uint,paid:bool --module meter -y # Display the content of one producer bill ## ## @@ -123,6 +123,8 @@ cp ./scripts/custo/meter/a_tools.go ./x/meter/keeper/ cp ./scripts/custo/meter/msg_server_prepare_bill.go ./x/meter/keeper/ cp ./scripts/custo/meter/a_meter_billing.go ./x/meter/keeper/ cp ./scripts/custo/meter/a_tools.go ./x/meter/keeper/ +# This module uses the SendCoins function of bankKeeper. We add this SendCoins function to : +cp ./scripts/custo/meter/expected_keepers.go ./x/meter/types/ ################################################################################################################## git add . git commit -am "Customize the code in meter module" diff --git a/vue/src/store/generated/electra.meter/index.ts b/vue/src/store/generated/electra.meter/index.ts index baeba75d..71ae6711 100644 --- a/vue/src/store/generated/electra.meter/index.ts +++ b/vue/src/store/generated/electra.meter/index.ts @@ -832,55 +832,55 @@ export default { }, - async sendMsgUpdateProducerbills({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgDeleteProducerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgUpdateProducerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgDeleteProducerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateProducerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteProducerbillingline:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgUpdateProducerbills:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgDeleteProducerbillingline:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgCreateCustomerbills({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgUpdatePowerPurchaseContract({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgCreateCustomerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgUpdatePowerPurchaseContract({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreateCustomerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdatePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgCreateCustomerbills:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgUpdatePowerPurchaseContract:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgRecord3({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgCreatePowerPurchaseContract({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgRecord3({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgCreatePowerPurchaseContract({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgRecord3:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreatePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgRecord3:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgCreatePowerPurchaseContract:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgPrepareBill({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgCreateBillingcycles({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgPrepareBill({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgCreateBillingcycles({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgPrepareBill:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreateBillingcycles:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgPrepareBill:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgCreateBillingcycles:Send Could not broadcast Tx: '+ e.message) } } }, @@ -897,303 +897,303 @@ export default { } } }, - async sendMsgCreateProducerbills({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgCreateCustomerbills({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgCreateProducerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgCreateCustomerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreateProducerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreateCustomerbills:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgCreateProducerbills:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgCreateCustomerbills:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgCreatePowerPurchaseContract({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgCreateProducerbills({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgCreatePowerPurchaseContract({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgCreateProducerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreatePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreateProducerbills:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgCreatePowerPurchaseContract:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgCreateProducerbills:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgUpdateBillingcycles({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgUpdateProducerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgUpdateBillingcycles({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgUpdateProducerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateBillingcycles:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateProducerbillingline:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgUpdateBillingcycles:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgUpdateProducerbillingline:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgDeleteCustomerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgUpdateCustomerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgDeleteCustomerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgUpdateCustomerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteCustomerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateCustomerbillingline:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgDeleteCustomerbillingline:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgUpdateCustomerbillingline:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgDeleteCustomerbills({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgCreatePpaMap({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgDeleteCustomerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgCreatePpaMap({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteCustomerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreatePpaMap:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgDeleteCustomerbills:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgCreatePpaMap:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgUpdatePpaMap({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgDeletePpaMap({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgUpdatePpaMap({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgDeletePpaMap({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdatePpaMap:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeletePpaMap:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgUpdatePpaMap:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgDeletePpaMap:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgCreatePpaMap({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgRecord({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgCreatePpaMap({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgRecord({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreatePpaMap:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgRecord:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgCreatePpaMap:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgRecord:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgUpdateCustomerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgDeleteCustomerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgUpdateCustomerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgDeleteCustomerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateCustomerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteCustomerbillingline:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgUpdateCustomerbillingline:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgDeleteCustomerbillingline:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgRecord({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgCreateProducerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgRecord({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgCreateProducerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgRecord:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreateProducerbillingline:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgRecord:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgCreateProducerbillingline:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgCreateProducerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgPrepareBill({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgCreateProducerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgPrepareBill({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreateProducerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgPrepareBill:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgCreateProducerbillingline:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgPrepareBill:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgUpdatePowerPurchaseContract({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgUpdateCustomerbills({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgUpdatePowerPurchaseContract({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgUpdateCustomerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdatePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateCustomerbills:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgUpdatePowerPurchaseContract:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgUpdateCustomerbills:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgDeleteBillingcycles({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgUpdatePpaMap({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgDeleteBillingcycles({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgUpdatePpaMap({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteBillingcycles:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdatePpaMap:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgDeleteBillingcycles:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgUpdatePpaMap:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgDeletePowerPurchaseContract({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgDeleteProducerbills({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgDeletePowerPurchaseContract({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgDeleteProducerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeletePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteProducerbills:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgDeletePowerPurchaseContract:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgDeleteProducerbills:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgCreateBillingcycles({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgDeleteCustomerbills({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgCreateBillingcycles({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgDeleteCustomerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreateBillingcycles:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteCustomerbills:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgCreateBillingcycles:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgDeleteCustomerbills:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgUpdateProducerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgRecord3({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgUpdateProducerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgRecord3({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateProducerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgRecord3:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgUpdateProducerbillingline:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgRecord3:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgDeleteProducerbillingline({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgUpdateBillingcycles({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgDeleteProducerbillingline({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgUpdateBillingcycles({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteProducerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateBillingcycles:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgDeleteProducerbillingline:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgUpdateBillingcycles:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgUpdateCustomerbills({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgDeletePowerPurchaseContract({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgUpdateCustomerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgDeletePowerPurchaseContract({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateCustomerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeletePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgUpdateCustomerbills:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgDeletePowerPurchaseContract:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgDeletePpaMap({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgDeleteBillingcycles({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgDeletePpaMap({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgDeleteBillingcycles({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeletePpaMap:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteBillingcycles:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgDeletePpaMap:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgDeleteBillingcycles:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgDeleteProducerbills({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgUpdateProducerbills({ rootGetters }, { value, fee = [], memo = '' }) { try { const client=await initClient(rootGetters) - const result = await client.ElectraMeter.tx.sendMsgDeleteProducerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) + const result = await client.ElectraMeter.tx.sendMsgUpdateProducerbills({ value, fee: {amount: fee, gas: "200000"}, memo }) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteProducerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateProducerbills:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgDeleteProducerbills:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgUpdateProducerbills:Send Could not broadcast Tx: '+ e.message) } } }, - async MsgUpdateProducerbills({ rootGetters }, { value }) { + async MsgDeleteProducerbillingline({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgUpdateProducerbills({value}) + const msg = await client.ElectraMeter.tx.msgDeleteProducerbillingline({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateProducerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteProducerbillingline:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgUpdateProducerbills:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgDeleteProducerbillingline:Create Could not create message: ' + e.message) } } }, - async MsgCreateCustomerbills({ rootGetters }, { value }) { + async MsgUpdatePowerPurchaseContract({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgCreateCustomerbills({value}) + const msg = await client.ElectraMeter.tx.msgUpdatePowerPurchaseContract({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreateCustomerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdatePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgCreateCustomerbills:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgUpdatePowerPurchaseContract:Create Could not create message: ' + e.message) } } }, - async MsgRecord3({ rootGetters }, { value }) { + async MsgCreatePowerPurchaseContract({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgRecord3({value}) + const msg = await client.ElectraMeter.tx.msgCreatePowerPurchaseContract({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgRecord3:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreatePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgRecord3:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgCreatePowerPurchaseContract:Create Could not create message: ' + e.message) } } }, - async MsgPrepareBill({ rootGetters }, { value }) { + async MsgCreateBillingcycles({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgPrepareBill({value}) + const msg = await client.ElectraMeter.tx.msgCreateBillingcycles({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgPrepareBill:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreateBillingcycles:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgPrepareBill:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgCreateBillingcycles:Create Could not create message: ' + e.message) } } }, @@ -1210,250 +1210,250 @@ export default { } } }, - async MsgCreateProducerbills({ rootGetters }, { value }) { + async MsgCreateCustomerbills({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgCreateProducerbills({value}) + const msg = await client.ElectraMeter.tx.msgCreateCustomerbills({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreateProducerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreateCustomerbills:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgCreateProducerbills:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgCreateCustomerbills:Create Could not create message: ' + e.message) } } }, - async MsgCreatePowerPurchaseContract({ rootGetters }, { value }) { + async MsgCreateProducerbills({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgCreatePowerPurchaseContract({value}) + const msg = await client.ElectraMeter.tx.msgCreateProducerbills({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreatePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreateProducerbills:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgCreatePowerPurchaseContract:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgCreateProducerbills:Create Could not create message: ' + e.message) } } }, - async MsgUpdateBillingcycles({ rootGetters }, { value }) { + async MsgUpdateProducerbillingline({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgUpdateBillingcycles({value}) + const msg = await client.ElectraMeter.tx.msgUpdateProducerbillingline({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateBillingcycles:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateProducerbillingline:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgUpdateBillingcycles:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgUpdateProducerbillingline:Create Could not create message: ' + e.message) } } }, - async MsgDeleteCustomerbillingline({ rootGetters }, { value }) { + async MsgUpdateCustomerbillingline({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgDeleteCustomerbillingline({value}) + const msg = await client.ElectraMeter.tx.msgUpdateCustomerbillingline({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteCustomerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateCustomerbillingline:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgDeleteCustomerbillingline:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgUpdateCustomerbillingline:Create Could not create message: ' + e.message) } } }, - async MsgDeleteCustomerbills({ rootGetters }, { value }) { + async MsgCreatePpaMap({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgDeleteCustomerbills({value}) + const msg = await client.ElectraMeter.tx.msgCreatePpaMap({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteCustomerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreatePpaMap:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgDeleteCustomerbills:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgCreatePpaMap:Create Could not create message: ' + e.message) } } }, - async MsgUpdatePpaMap({ rootGetters }, { value }) { + async MsgDeletePpaMap({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgUpdatePpaMap({value}) + const msg = await client.ElectraMeter.tx.msgDeletePpaMap({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdatePpaMap:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeletePpaMap:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgUpdatePpaMap:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgDeletePpaMap:Create Could not create message: ' + e.message) } } }, - async MsgCreatePpaMap({ rootGetters }, { value }) { + async MsgRecord({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgCreatePpaMap({value}) + const msg = await client.ElectraMeter.tx.msgRecord({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreatePpaMap:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgRecord:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgCreatePpaMap:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgRecord:Create Could not create message: ' + e.message) } } }, - async MsgUpdateCustomerbillingline({ rootGetters }, { value }) { + async MsgDeleteCustomerbillingline({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgUpdateCustomerbillingline({value}) + const msg = await client.ElectraMeter.tx.msgDeleteCustomerbillingline({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateCustomerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteCustomerbillingline:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgUpdateCustomerbillingline:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgDeleteCustomerbillingline:Create Could not create message: ' + e.message) } } }, - async MsgRecord({ rootGetters }, { value }) { + async MsgCreateProducerbillingline({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgRecord({value}) + const msg = await client.ElectraMeter.tx.msgCreateProducerbillingline({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgRecord:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgCreateProducerbillingline:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgRecord:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgCreateProducerbillingline:Create Could not create message: ' + e.message) } } }, - async MsgCreateProducerbillingline({ rootGetters }, { value }) { + async MsgPrepareBill({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgCreateProducerbillingline({value}) + const msg = await client.ElectraMeter.tx.msgPrepareBill({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreateProducerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgPrepareBill:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgCreateProducerbillingline:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgPrepareBill:Create Could not create message: ' + e.message) } } }, - async MsgUpdatePowerPurchaseContract({ rootGetters }, { value }) { + async MsgUpdateCustomerbills({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgUpdatePowerPurchaseContract({value}) + const msg = await client.ElectraMeter.tx.msgUpdateCustomerbills({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdatePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateCustomerbills:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgUpdatePowerPurchaseContract:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgUpdateCustomerbills:Create Could not create message: ' + e.message) } } }, - async MsgDeleteBillingcycles({ rootGetters }, { value }) { + async MsgUpdatePpaMap({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgDeleteBillingcycles({value}) + const msg = await client.ElectraMeter.tx.msgUpdatePpaMap({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteBillingcycles:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdatePpaMap:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgDeleteBillingcycles:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgUpdatePpaMap:Create Could not create message: ' + e.message) } } }, - async MsgDeletePowerPurchaseContract({ rootGetters }, { value }) { + async MsgDeleteProducerbills({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgDeletePowerPurchaseContract({value}) + const msg = await client.ElectraMeter.tx.msgDeleteProducerbills({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeletePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteProducerbills:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgDeletePowerPurchaseContract:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgDeleteProducerbills:Create Could not create message: ' + e.message) } } }, - async MsgCreateBillingcycles({ rootGetters }, { value }) { + async MsgDeleteCustomerbills({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgCreateBillingcycles({value}) + const msg = await client.ElectraMeter.tx.msgDeleteCustomerbills({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgCreateBillingcycles:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteCustomerbills:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgCreateBillingcycles:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgDeleteCustomerbills:Create Could not create message: ' + e.message) } } }, - async MsgUpdateProducerbillingline({ rootGetters }, { value }) { + async MsgRecord3({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgUpdateProducerbillingline({value}) + const msg = await client.ElectraMeter.tx.msgRecord3({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateProducerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgRecord3:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgUpdateProducerbillingline:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgRecord3:Create Could not create message: ' + e.message) } } }, - async MsgDeleteProducerbillingline({ rootGetters }, { value }) { + async MsgUpdateBillingcycles({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgDeleteProducerbillingline({value}) + const msg = await client.ElectraMeter.tx.msgUpdateBillingcycles({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteProducerbillingline:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateBillingcycles:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgDeleteProducerbillingline:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgUpdateBillingcycles:Create Could not create message: ' + e.message) } } }, - async MsgUpdateCustomerbills({ rootGetters }, { value }) { + async MsgDeletePowerPurchaseContract({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgUpdateCustomerbills({value}) + const msg = await client.ElectraMeter.tx.msgDeletePowerPurchaseContract({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgUpdateCustomerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeletePowerPurchaseContract:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgUpdateCustomerbills:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgDeletePowerPurchaseContract:Create Could not create message: ' + e.message) } } }, - async MsgDeletePpaMap({ rootGetters }, { value }) { + async MsgDeleteBillingcycles({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgDeletePpaMap({value}) + const msg = await client.ElectraMeter.tx.msgDeleteBillingcycles({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeletePpaMap:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgDeleteBillingcycles:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgDeletePpaMap:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgDeleteBillingcycles:Create Could not create message: ' + e.message) } } }, - async MsgDeleteProducerbills({ rootGetters }, { value }) { + async MsgUpdateProducerbills({ rootGetters }, { value }) { try { const client=initClient(rootGetters) - const msg = await client.ElectraMeter.tx.msgDeleteProducerbills({value}) + const msg = await client.ElectraMeter.tx.msgUpdateProducerbills({value}) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgDeleteProducerbills:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgUpdateProducerbills:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgDeleteProducerbills:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgUpdateProducerbills:Create Could not create message: ' + e.message) } } }, diff --git a/x/meter/keeper/a_meter_billing.go b/x/meter/keeper/a_meter_billing.go index 6f3deb8f..25e31f0e 100644 --- a/x/meter/keeper/a_meter_billing.go +++ b/x/meter/keeper/a_meter_billing.go @@ -504,7 +504,7 @@ for customerDeviceID, _ := range currentCycleConsumeInMap { // makePrepareBill return customerbill, customerBillLines, producerBillLines, comment, err } -func (k msgServer) recordAllPreparedBills(goCtx context.Context, customerBill map[string]types.Customerbills, customerBillingLines []types.Customerbillingline, producerBillingLines []types.Producerbillingline)( string, error){ +func (k msgServer) recordAllPreparedBills(goCtx context.Context, customerBill map[string]types.Customerbills, customerBillingLines []types.Customerbillingline, producerBillingLines []types.Producerbillingline, executePayment bool)( string, error){ // Performance Management start := time.Now() ctx := sdk.UnwrapSDKContext(goCtx) @@ -521,8 +521,8 @@ func (k msgServer) recordAllPreparedBills(goCtx context.Context, customerBill ma errmsg := fmt.Sprintf("# recordAllPreparedBills # Error: index already set Cycle:%d Customer:%s\n", cbill.BillCycleID, cbill.CustomerDeviceID ) comment += errmsg } else { - if (cbill.BillTotalPrice>0) { - // set the specific customerbillingline in the store from its index + if (cbill.BillTotalPrice>0) { + // set the specific customerbilling in the store from its index k.SetCustomerbills( ctx, cbill, @@ -548,7 +548,34 @@ func (k msgServer) recordAllPreparedBills(goCtx context.Context, customerBill ma // sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, errmsg) } else { if (cbill.LineWhTotalPrice>0) { - // set the specific customerbillingline in the store from its index + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Proceed to the payment + // Note: This module uses the SendCoins function of bankKeeper so Add SendCoins to x/meter/types/expected_keepers.go + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + if (executePayment == true ) { + customer, _ := sdk.AccAddressFromBech32(cbill.CustomerDeviceID) + producer, _ := sdk.AccAddressFromBech32(cbill.ProducerDeviceID) + amount, err := sdk.ParseCoinsNormalized(string(cbill.LineWhTotalPrice) + cbill.Curency) + if err != nil { + errmsg := "Cannot parse coins in invoice amount" + comment += errmsg + //return nil, sdkerrors.Wrap(types.ErrWrongLoanState, errmsg) + } + // send tokens from the customer to the producer + err = k.bankKeeper.SendCoins(ctx, customer, producer, amount) + if err != nil { + errmsg := "Sendcoin failed to send coins" + comment += errmsg + //return nil, sdkerrors.Wrap(types.ErrWrongLoanState, "Cannot parse coins in loan amount") + } else { + // Update the bill with the payment result + // cbill.Paid = true + } + } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // END payment + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // set the specific billingline in the store from its index k.SetCustomerbillingline( ctx, cbill, diff --git a/x/meter/keeper/msg_server_prepare_bill.go b/x/meter/keeper/msg_server_prepare_bill.go index 93e119bd..7efc641a 100644 --- a/x/meter/keeper/msg_server_prepare_bill.go +++ b/x/meter/keeper/msg_server_prepare_bill.go @@ -20,6 +20,7 @@ func (k msgServer) PrepareBill(goCtx context.Context, msg *types.MsgPrepareBill) start := time.Now() // Variables ctx := sdk.UnwrapSDKContext(goCtx) + var executePayment = true // var executePayment = msg.ExecutePayment var comment string = "" var ppcList []types.PowerPurchaseContract = k.GetAllPowerPurchaseContract(ctx) // from x/meter/keeper/power_purchase_contract.go var ppaList []types.PpaMap = k.GetAllPpaMap(ctx) // from x/meter/keeper/ppa_map.go GetAllPpaMap returns all ppaMap func (k Keeper) GetAllPpaMap(ctx sdk.Context) (list []types.PpaMap) @@ -34,7 +35,7 @@ func (k msgServer) PrepareBill(goCtx context.Context, msg *types.MsgPrepareBill) customerbill, customerbillinglines, producerbillinglines, commentPrepare, err := makePrepareBill(ppcMap, ppaMap, msg.CycleID, previousCycleConsumeInMap, previousCycleProduceOutMap, currentCycleConsumeInMap, currentCycleProduceOutMap) if (msg.Record == true) { // Record the bill on the chain - commentRecord, _ := k.recordAllPreparedBills(goCtx, customerbill, customerbillinglines, producerbillinglines) + commentRecord, _ := k.recordAllPreparedBills(goCtx, customerbill, customerbillinglines, producerbillinglines, executePayment) comment += commentRecord } comment += fmt.Sprintf("\n### PrepareBill ###\ncustomerbill:%+v\ncustomerbillinglines:%+v\nproducerbillinglines:%+v\n",customerbill, customerbillinglines, producerbillinglines, commentPrepare) diff --git a/x/meter/types/expected_keepers.go b/x/meter/types/expected_keepers.go index 6aa6e977..06c28642 100644 --- a/x/meter/types/expected_keepers.go +++ b/x/meter/types/expected_keepers.go @@ -14,5 +14,6 @@ type AccountKeeper interface { // BankKeeper defines the expected interface needed to retrieve account balances. type BankKeeper interface { SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error // Methods imported from bank should be defined here }