2020-10-28 06:36:49 +01:00
|
|
|
package stake
|
2017-09-12 18:02:30 +02:00
|
|
|
|
|
|
|
import (
|
2017-11-20 19:44:19 +01:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-10-28 06:36:49 +01:00
|
|
|
|
2017-09-12 18:02:30 +02:00
|
|
|
"github.com/golang/protobuf/jsonpb"
|
|
|
|
)
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
func marshalToString(c *Helper) (string, error) {
|
|
|
|
mPb := &jsonpb.Marshaler{}
|
2020-10-28 06:36:49 +01:00
|
|
|
if c.IsSupport() {
|
2021-10-06 20:00:59 +02:00
|
|
|
return mPb.MarshalToString(c.Support)
|
2020-10-28 06:36:49 +01:00
|
|
|
}
|
2021-10-06 20:00:59 +02:00
|
|
|
return mPb.MarshalToString(c.Claim)
|
2017-09-12 18:02:30 +02:00
|
|
|
}
|
2017-11-08 03:39:08 +01:00
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
func (c *Helper) RenderJSON() (string, error) {
|
2017-11-20 19:44:19 +01:00
|
|
|
r, err := marshalToString(c)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("err")
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
var dat map[string]interface{}
|
|
|
|
err = json.Unmarshal([]byte(r), &dat)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return r, nil
|
2017-11-08 03:39:08 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 19:44:19 +01:00
|
|
|
//TODO: encode byte arrays with b58 for addresses and b16 for source hashes instead of the default of b64
|