mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-07-06 12:42:30 +00:00

* aggregating error messages * removed duplicate err msgs * removed obsolete test (two times equal behaviour ) * added global error msg module * refactored test utils to have sample types and sample objects by keepers separated * excluded auto-generated code from sonarcube analysis Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
99 lines
2.8 KiB
Go
99 lines
2.8 KiB
Go
package moduleobject
|
|
|
|
import (
|
|
"encoding/hex"
|
|
|
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
"github.com/planetmint/planetmint-go/config"
|
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
|
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
|
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
|
"github.com/cosmos/go-bip39"
|
|
)
|
|
|
|
func ExtendedKeyPair(cfg chaincfg.Params) (string, string) {
|
|
seed, err := bip39.NewSeedWithErrorChecking(sample.Mnemonic, keyring.DefaultBIP39Passphrase)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
xprivKey, err := hdkeychain.NewMaster(seed, &cfg)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
xpubKey, err := xprivKey.Neuter()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return xprivKey.String(), xpubKey.String()
|
|
}
|
|
|
|
// Machine creates a new machine object
|
|
// TODO: make address deterministic for test cases
|
|
func Machine(name, pubKey string, prvKey string, address string) machinetypes.Machine {
|
|
metadata := Metadata()
|
|
_, liquidPubKey := ExtendedKeyPair(config.LiquidNetParams)
|
|
_, planetmintPubKey := ExtendedKeyPair(config.PlmntNetParams)
|
|
|
|
prvKeyBytes, _ := hex.DecodeString(prvKey)
|
|
sk := &secp256k1.PrivKey{Key: prvKeyBytes}
|
|
pubKeyBytes, _ := hex.DecodeString(pubKey)
|
|
sign, _ := sk.Sign(pubKeyBytes)
|
|
signatureHex := hex.EncodeToString(sign)
|
|
|
|
if address == "" {
|
|
address = sample.Secp256k1AccAddress().String()
|
|
}
|
|
|
|
m := machinetypes.Machine{
|
|
Name: name,
|
|
Ticker: name + "_ticker",
|
|
Domain: "lab.r3c.network",
|
|
Reissue: true,
|
|
Amount: 1000,
|
|
Precision: 8,
|
|
IssuerPlanetmint: planetmintPubKey,
|
|
IssuerLiquid: liquidPubKey,
|
|
MachineId: pubKey,
|
|
Metadata: &metadata,
|
|
Type: 1,
|
|
MachineIdSignature: signatureHex,
|
|
Address: address,
|
|
}
|
|
return m
|
|
}
|
|
|
|
func MachineIndex(pubKey string, planetmintPubKey string, liquidPubKey string) machinetypes.MachineIndex {
|
|
return machinetypes.MachineIndex{
|
|
MachineId: pubKey,
|
|
IssuerPlanetmint: planetmintPubKey,
|
|
IssuerLiquid: liquidPubKey,
|
|
}
|
|
}
|
|
|
|
func Metadata() machinetypes.Metadata {
|
|
return machinetypes.Metadata{
|
|
Gps: "{\"Latitude\":\"-48.876667\",\"Longitude\":\"-123.393333\"}",
|
|
Device: "{\"Manufacturer\": \"RDDL\",\"Serial\":\"AdnT2uyt\"}",
|
|
AssetDefinition: "{\"Version\": \"0.1\"}",
|
|
AdditionalDataCID: "CID",
|
|
}
|
|
}
|
|
|
|
func TrustAnchor(pubkey string) machinetypes.TrustAnchor {
|
|
return machinetypes.TrustAnchor{
|
|
Pubkey: pubkey,
|
|
}
|
|
}
|
|
|
|
func MintRequest(beneficiaryAddr string, amount uint64, txhash string) daotypes.MintRequest {
|
|
return daotypes.MintRequest{
|
|
Beneficiary: beneficiaryAddr,
|
|
Amount: amount,
|
|
LiquidTxHash: txhash,
|
|
}
|
|
}
|