mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-07 22:56:37 +00:00
hotfix: inconsistent logging of block-proposer results on the chain. … (#153)
* hotfix: inconsistent logging of block-proposer results on the chain. These results need to be consensed via an explicit message instead of an error output. Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
126d59cff9
commit
c6909a3e4a
@ -3,12 +3,8 @@ package keeper
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
config "github.com/planetmint/planetmint-go/config"
|
config "github.com/planetmint/planetmint-go/config"
|
||||||
@ -50,10 +46,11 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
|
|||||||
}
|
}
|
||||||
|
|
||||||
if k.isNFTCreationRequest(msg.Machine) && util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) {
|
if k.isNFTCreationRequest(msg.Machine) && util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) {
|
||||||
err := k.issueMachineNFT(msg.Machine)
|
_ = k.issueMachineNFT(msg.Machine)
|
||||||
if err != nil {
|
//TODO create NFTCreationMessage to be stored by all nodes
|
||||||
return nil, types.ErrNFTIssuanceFailed
|
// if err != nil {
|
||||||
}
|
// return nil, types.ErrNFTIssuanceFailed
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Machine.GetType() == 0 { // 0 == RDDL_MACHINE_UNDEFINED
|
if msg.Machine.GetType() == 0 { // 0 == RDDL_MACHINE_UNDEFINED
|
||||||
@ -98,7 +95,7 @@ func (k msgServer) issueNFTAsset(name string, machine_address string) (asset_id
|
|||||||
// Execute the command
|
// Execute the command
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("cmd.Run() failed with %s\n", err)
|
log.Printf("cmd.Run() failed with %s\n", err)
|
||||||
err = errorsmod.Wrap(types.ErrMachineNFTIssuance, stderr.String())
|
err = errorsmod.Wrap(types.ErrMachineNFTIssuance, stderr.String())
|
||||||
} else {
|
} else {
|
||||||
lines := strings.Split(stdout.String(), "\n")
|
lines := strings.Split(stdout.String(), "\n")
|
||||||
@ -111,58 +108,14 @@ func (k msgServer) issueNFTAsset(name string, machine_address string) (asset_id
|
|||||||
}
|
}
|
||||||
return asset_id, contract, err
|
return asset_id, contract, err
|
||||||
}
|
}
|
||||||
func (k msgServer) registerAsset(asset_id string, contract string) error {
|
|
||||||
|
|
||||||
conf := config.GetConfig()
|
|
||||||
|
|
||||||
// Create your request payload
|
|
||||||
data := map[string]interface{}{
|
|
||||||
"asset_id": asset_id,
|
|
||||||
"contract": contract,
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonData, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
|
||||||
return errorsmod.Wrap(types.ErrAssetRegistryReqFailure, "Marshall "+err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", conf.AssetRegistryEndpoint, bytes.NewBuffer(jsonData))
|
|
||||||
if err != nil {
|
|
||||||
return errorsmod.Wrap(types.ErrAssetRegistryReqFailure, "Request creation: "+err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set headers
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
req.Header.Set("accept", "application/json")
|
|
||||||
|
|
||||||
// Send request
|
|
||||||
client := &http.Client{}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return errorsmod.Wrap(types.ErrAssetRegistryReqSending, err.Error())
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
// Read response
|
|
||||||
if resp.StatusCode > 299 {
|
|
||||||
return errorsmod.Wrap(types.ErrAssetRegistryRepsonse, "Error reading response body:"+strconv.Itoa(resp.StatusCode))
|
|
||||||
}
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return errorsmod.Wrap(types.ErrAssetRegistryRepsonse, "Error reading response body:"+err.Error())
|
|
||||||
}
|
|
||||||
result_obj := string(body)
|
|
||||||
if strings.Contains(result_obj, asset_id) {
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
return errorsmod.Wrap(types.ErrAssetRegistryRepsonse, "does not confirm asset registration")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (k msgServer) issueMachineNFT(machine *types.Machine) error {
|
func (k msgServer) issueMachineNFT(machine *types.Machine) error {
|
||||||
asset_id, contract, err := k.issueNFTAsset(machine.Name, machine.Address)
|
_, _, err := k.issueNFTAsset(machine.Name, machine.Address)
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
// asset registration is not performed in case of NFT issuance for machines
|
||||||
return k.registerAsset(asset_id, contract)
|
//asset_id, contract, err := k.issueNFTAsset(machine.Name, machine.Address)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
//return k.registerAsset(asset_id, contract)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user