mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 06:25:47 +00:00
added nft notarization for DER
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
a9ba74fd59
commit
67e6e1dc05
@ -125,6 +125,7 @@ import (
|
||||
dermodule "github.com/planetmint/planetmint-go/x/der"
|
||||
dermodulekeeper "github.com/planetmint/planetmint-go/x/der/keeper"
|
||||
dermoduletypes "github.com/planetmint/planetmint-go/x/der/types"
|
||||
|
||||
// this line is used by starport scaffolding # stargate/app/moduleImport
|
||||
|
||||
pmante "github.com/planetmint/planetmint-go/app/ante"
|
||||
@ -594,6 +595,8 @@ func New(
|
||||
keys[dermoduletypes.StoreKey],
|
||||
keys[dermoduletypes.MemStoreKey],
|
||||
app.GetSubspace(dermoduletypes.ModuleName),
|
||||
app.MachineKeeper,
|
||||
homePath,
|
||||
)
|
||||
derModule := dermodule.NewAppModule(appCodec, app.DerKeeper, app.AccountKeeper, app.BankKeeper)
|
||||
|
||||
|
||||
@ -41,6 +41,8 @@ func DerKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||
storeKey,
|
||||
memStoreKey,
|
||||
paramsSubspace,
|
||||
nil, // No need for machine keeper in this test
|
||||
"",
|
||||
)
|
||||
|
||||
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"github.com/planetmint/planetmint-go/config"
|
||||
"github.com/planetmint/planetmint-go/lib"
|
||||
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
||||
dertypes "github.com/planetmint/planetmint-go/x/der/types"
|
||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
@ -87,6 +88,13 @@ func SendLiquidAssetRegistration(goCtx context.Context, notarizedAsset machinety
|
||||
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
||||
}
|
||||
|
||||
func SendLiquidDerAssetRegistration(goCtx context.Context, notarizedAsset dertypes.LiquidDerAsset) {
|
||||
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
|
||||
msg := dertypes.NewMsgNotarizeLiquidDerAsset(sendingValidatorAddress, ¬arizedAsset)
|
||||
loggingContext := "notarize liquid DER asset"
|
||||
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
|
||||
}
|
||||
|
||||
func SendInitPoP(goCtx context.Context, challenger string, challengee string, blockHeight int64) {
|
||||
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
|
||||
msg := daotypes.NewMsgInitPop(sendingValidatorAddress, sendingValidatorAddress, challenger, challengee, blockHeight)
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/planetmint/planetmint-go/clients/shamir/coordinator"
|
||||
derTypes "github.com/planetmint/planetmint-go/x/der/types"
|
||||
"github.com/planetmint/planetmint-go/x/machine/types"
|
||||
)
|
||||
|
||||
@ -28,6 +29,32 @@ func init() {
|
||||
RegisterAssetServiceHTTPClient = &http.Client{}
|
||||
}
|
||||
|
||||
func IssueDerNFT(goCtx context.Context, der *derTypes.DER, scheme string, domain string, path string) error {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
// asset registration is in order to have the contact published
|
||||
var notarizedAsset derTypes.LiquidDerAsset
|
||||
|
||||
assetID, contract, hex, err := coordinator.IssueNFTAsset(goCtx, der.ZigbeeID, der.PlmntAddress, domain)
|
||||
if err != nil {
|
||||
GetAppLogger().Error(ctx, err, "")
|
||||
return err
|
||||
}
|
||||
assetRegistryEndpoint := fmt.Sprintf("%s://%s/%s", scheme, domain, path)
|
||||
|
||||
GetAppLogger().Info(ctx, "Liquid Token Issuance assetID: "+assetID+" contract: "+contract+" tx: "+hex)
|
||||
err = RegisterAsset(goCtx, assetID, contract, assetRegistryEndpoint)
|
||||
if err != nil {
|
||||
GetAppLogger().Error(ctx, err, "")
|
||||
}
|
||||
// issue message with:
|
||||
notarizedAsset.AssetID = assetID
|
||||
notarizedAsset.ZigbeeID = der.ZigbeeID
|
||||
notarizedAsset.PlmntAddress = der.PlmntAddress
|
||||
|
||||
SendLiquidDerAssetRegistration(goCtx, notarizedAsset)
|
||||
return err
|
||||
}
|
||||
|
||||
func IssueMachineNFT(goCtx context.Context, machine *types.Machine, scheme string, domain string, path string) error {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
// asset registration is in order to have the contact published
|
||||
|
||||
@ -18,6 +18,8 @@ type (
|
||||
storeKey storetypes.StoreKey
|
||||
memKey storetypes.StoreKey
|
||||
paramstore paramtypes.Subspace
|
||||
MachineKeeper types.MachineKeeper // reference to machine keeper
|
||||
rootDir string
|
||||
}
|
||||
)
|
||||
|
||||
@ -26,7 +28,8 @@ func NewKeeper(
|
||||
storeKey,
|
||||
memKey storetypes.StoreKey,
|
||||
ps paramtypes.Subspace,
|
||||
|
||||
machineKeeper types.MachineKeeper, // add machineKeeper param
|
||||
rootDir string,
|
||||
) *Keeper {
|
||||
// set KeyTable if it has not already been set
|
||||
if !ps.HasKeyTable() {
|
||||
@ -38,6 +41,8 @@ func NewKeeper(
|
||||
storeKey: storeKey,
|
||||
memKey: memKey,
|
||||
paramstore: ps,
|
||||
MachineKeeper: machineKeeper, // set field
|
||||
rootDir: rootDir,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/planetmint/planetmint-go/util"
|
||||
"github.com/planetmint/planetmint-go/x/der/types"
|
||||
machinesTypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||
)
|
||||
|
||||
func (k msgServer) RegisterDER(goCtx context.Context, msg *types.MsgRegisterDER) (*types.MsgRegisterDERResponse, error) {
|
||||
@ -13,12 +14,12 @@ func (k msgServer) RegisterDER(goCtx context.Context, msg *types.MsgRegisterDER)
|
||||
|
||||
k.StoreDerAttest(ctx, *msg.Der)
|
||||
|
||||
//TODO: init NFT creation and storag of NFT to DER associations
|
||||
// Get machine params from MachineKeeper
|
||||
params := k.MachineKeeper.GetParams(ctx)
|
||||
|
||||
// Process NFT issuance if validator is block proposer
|
||||
if util.IsValidatorBlockProposer(ctx, k.rootDir) {
|
||||
if err := k.handleDERNFTIssuance(goCtx, *msg.Der, params); err != nil {
|
||||
return err
|
||||
}
|
||||
k.handleDERNFTIssuance(goCtx, msg.Der, params)
|
||||
} else {
|
||||
util.GetAppLogger().Info(ctx, "Not block proposer: skipping DER NFT issuance")
|
||||
}
|
||||
@ -26,22 +27,22 @@ func (k msgServer) RegisterDER(goCtx context.Context, msg *types.MsgRegisterDER)
|
||||
return &types.MsgRegisterDERResponse{}, nil
|
||||
}
|
||||
|
||||
func (k msgServer) handleDERNFTIssuance(goCtx context.Context, machine *types.Machine, params types.Params) error {
|
||||
func (k msgServer) handleDERNFTIssuance(goCtx context.Context, der *types.DER, params machinesTypes.Params) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
logger := util.GetAppLogger()
|
||||
logger.Info(ctx, "Issuing Machine NFT: "+machine.String())
|
||||
logger.Info(ctx, "Issuing DER NFT: "+der.String())
|
||||
|
||||
err := util.IssueMachineNFT(goCtx, machine,
|
||||
err := util.IssueDerNFT(goCtx, der,
|
||||
params.AssetRegistryScheme,
|
||||
params.AssetRegistryDomain,
|
||||
params.AssetRegistryPath,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logger.Error(ctx, err, "Machine NFT issuance failed")
|
||||
return err
|
||||
logger.Error(ctx, err, "DER NFT issuance failed")
|
||||
return
|
||||
}
|
||||
|
||||
logger.Info(ctx, "Machine NFT issuance successful: "+machine.String())
|
||||
return nil
|
||||
logger.Info(ctx, "DER NFT issuance successful: "+der.ZigbeeID)
|
||||
return
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
machineTypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||
)
|
||||
|
||||
// AccountKeeper defines the expected account keeper used for simulations (noalias)
|
||||
@ -16,3 +17,9 @@ type BankKeeper interface {
|
||||
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
|
||||
// Methods imported from bank should be defined here
|
||||
}
|
||||
|
||||
// MachineKeeper defines the expected interface for the machine keeper
|
||||
// to allow DER module to access machine parameters.
|
||||
type MachineKeeper interface {
|
||||
GetParams(ctx sdk.Context) machineTypes.Params
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user