Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
asuleymanov committed Mar 17, 2020
1 parent ea32a0b commit ef5fbc2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 68 deletions.
26 changes: 17 additions & 9 deletions example/TemplateOperation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@ import (
"github.com/asuleymanov/golos-go/operations"
)

var(
weight int16 = 0
pkey = "<Privat Posting Key>"
user = "<UserName>"
author = "<AuthorName>"
link = "<Permlink>"
)

func main() {
cls, _ := golos.NewClient("wss://golos.solox.world/ws")
defer cls.Close()

cls.SetKeys(&golos.Keys{PKey: []string{"<Privat Posting Key>"}})
cls.SetKeys(&golos.Keys{PKey: []string{pkey}})

var trx []types.Operation
var trx []operations.Operation

tx := &types.VoteOperation{
Voter: "<UserName>",
Author: "<AuthorName>",
Permlink: "<Permlink>",
Weight: types.Int16(Weight),
tx := &operations.VoteOperation{
Voter: user,
Author: author,
Permlink: link,
Weight: weight,
}
trx = append(trx, tx)

resp, err := client.SendTrx("<UserName>", trx)
resp, err := cls.SendTrx(user, trx)
if err != nil {
fmt.Println("Error : ", err)
} else {
fmt.Println("Answer : ", resp)
}
}
}
38 changes: 38 additions & 0 deletions operations/custom_json_body.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package operations


var (
TypeFollow = "follow"
TypeReblog = "reblog"
TypeDeleteReblog = "delete_reblog"
)

var customJSONDataObjects = map[string]interface{}{
TypeFollow: &FollowOperation{},
TypeReblog: &ReblogOperation{},
TypeDeleteReblog: &DeleteReblogOperation{},
}

//FollowOperation the structure for the operation CustomJSONOperation.
type FollowOperation struct {
Follower string `json:"follower"`
Following string `json:"following"`
What []string `json:"what"`
}

//ReblogOperation the structure for the operation CustomJSONOperation.
type ReblogOperation struct {
Account string `json:"account"`
Author string `json:"author"`
Permlink string `json:"permlink"`
Title string `json:"title"`
Body string `json:"body"`
JSONMetadata string `json:"json_metadata"`
}

//DeleteReblogOperation the structure for the operation CustomJSONOperation.
type DeleteReblogOperation struct {
Account string `json:"account"`
Author string `json:"author"`
Permlink string `json:"permlink"`
}
72 changes: 13 additions & 59 deletions operations/operation_custom_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ import (
"github.com/asuleymanov/golos-go/encoding/transaction"
)

var (
TypeFollow = "follow"
TypeReblog = "reblog"
TypeLogin = "login"
TypePrivateMessage = "private_message"
)

var customJSONDataObjects = map[string]interface{}{
TypeFollow: &FollowOperation{},
TypeReblog: &ReblogOperation{},
TypeLogin: &LoginOperation{},
TypePrivateMessage: &PrivateMessageOperation{},
}

//CustomJSONOperation represents custom_json operation data.
type CustomJSONOperation struct {
RequiredAuths []string `json:"required_auths"`
Expand Down Expand Up @@ -79,47 +65,6 @@ func (op *CustomJSONOperation) UnmarshalData() (interface{}, error) {
return opData, nil
}

//MarshalTransaction is a function of converting type CustomJSONOperation to bytes.
func (op *CustomJSONOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeCustomJSON.Code()))
enc.EncodeArrString(op.RequiredAuths)
enc.EncodeArrString(op.RequiredPostingAuths)
enc.Encode(op.ID)
enc.Encode(op.JSON)
return enc.Err()
}

//FollowOperation the structure for the operation CustomJSONOperation.
type FollowOperation struct {
Follower string `json:"follower"`
Following string `json:"following"`
What []string `json:"what"`
}

//ReblogOperation the structure for the operation CustomJSONOperation.
type ReblogOperation struct {
Account string `json:"account"`
Author string `json:"author"`
Permlink string `json:"permlink"`
}

//LoginOperation the structure for the operation CustomJSONOperation.
type LoginOperation struct {
Account string `json:"account"`
}

//PrivateMessageOperation the structure for the operation CustomJSONOperation.
type PrivateMessageOperation struct {
From string `json:"from"`
To string `json:"to"`
FromMemoKey string `json:"from_memo_key"`
ToMemoKey string `json:"to_memo_key"`
SentTime uint64 `json:"sent_time"`
Checksum uint32 `json:"checksum"`
EncryptedMessage string `json:"encrypted_message"`
}

//MarshalCustomJSON generate a row from the structure fields.
func MarshalCustomJSON(v interface{}) (string, error) {
var tmp []interface{}
Expand All @@ -130,10 +75,8 @@ func MarshalCustomJSON(v interface{}) (string, error) {
tmp = append(tmp, TypeFollow)
case "ReblogOperation":
tmp = append(tmp, TypeReblog)
case "LoginOperation":
tmp = append(tmp, TypeLogin)
case "PrivateMessageOperation":
tmp = append(tmp, TypePrivateMessage)
case "DeleteReblogOperation":
tmp = append(tmp, TypeDeleteReblog)
default:
return "", errors.New("Unknown type")
}
Expand All @@ -147,3 +90,14 @@ func MarshalCustomJSON(v interface{}) (string, error) {

return string(b), nil //strings.Replace(string(b), "\"", "\\\"", -1), nil
}

//MarshalTransaction is a function of converting type CustomJSONOperation to bytes.
func (op *CustomJSONOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeCustomJSON.Code()))
enc.EncodeArrString(op.RequiredAuths)
enc.EncodeArrString(op.RequiredPostingAuths)
enc.Encode(op.ID)
enc.Encode(op.JSON)
return enc.Err()
}

0 comments on commit ef5fbc2

Please sign in to comment.