Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
Fix Bug UTF-8 Special symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
asuleymanov committed Sep 28, 2017
1 parent 4244660 commit 0be8864
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 16 deletions.
39 changes: 38 additions & 1 deletion client/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (api *Client) Transfer(from_name, to_name, memo, ammount string) error {
}
resp, err := api.Send_Trx(from_name, tx)
if err != nil {
return errors.Wrapf(err, "Error Reblog: ")
return errors.Wrapf(err, "Error Transfer: ")
} else {
log.Println("[Transfer] Block -> ", resp.BlockNum, " From user -> ", from_name, " To user -> ", to_name)
return nil
Expand Down Expand Up @@ -468,3 +468,40 @@ func (api *Client) Login(user_name, pass string) bool {
return true
}
}

func (api *Client) FeedPublish(username, base, quote string) error {

ExchR := types.ExchRate{Base: base, Quote: quote}
tx := &types.FeedPublishOperation{
Publisher: username,
ExchangeRate: ExchR,
}

resp, err := api.Send_Trx(username, tx)
if err != nil {
return errors.Wrapf(err, "Error FeedPublish: ")
} else {
log.Println("[FeedPublish] Block -> ", resp.BlockNum, " FeedPublish user -> ", username)
return nil
}
}

func (api *Client) WitnessUpdate(username, url, signKey, acfee, fee string, blocksize uint32, sbdir uint16) error {

chprop := types.ChainProperties{AccountCreationFee: acfee, MaximumBlockSize: blocksize, SBDInterestRate: sbdir}
tx := &types.WitnessUpdateOperation{
Owner: username,
Url: url,
BlockSigningKey: signKey,
Props: &chprop,
Fee: fee,
}

resp, err := api.Send_Trx(username, tx)
if err != nil {
return errors.Wrapf(err, "Error WitnessUpdate: ")
} else {
log.Println("[WitnessUpdate] Block -> ", resp.BlockNum, " WitnessUpdate user -> ", username)
return nil
}
}
8 changes: 4 additions & 4 deletions client/ident_wif.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,25 @@ func (api *Client) Signing_Keys(username string, trx types.Operation) [][]byte {
for _, val := range op_keys {
switch {
case val == "posting":
privKey, err := wif.Decode(string([]byte(Key_List[username].PKey)))
privKey, err := wif.Decode(Key_List[username].PKey)
if err != nil {
log.Println(errors.Wrapf(err, "Error decode Key: "))
}
keys = append(keys, privKey)
case val == "active":
privKey, err := wif.Decode(string([]byte(Key_List[username].AKey)))
privKey, err := wif.Decode(Key_List[username].AKey)
if err != nil {
log.Println(errors.Wrapf(err, "Error decode Key: "))
}
keys = append(keys, privKey)
case val == "owner":
privKey, err := wif.Decode(string([]byte(Key_List[username].OKey)))
privKey, err := wif.Decode(Key_List[username].OKey)
if err != nil {
log.Println(errors.Wrapf(err, "Error decode Key: "))
}
keys = append(keys, privKey)
case val == "memo":
privKey, err := wif.Decode(string([]byte(Key_List[username].MKey)))
privKey, err := wif.Decode(Key_List[username].MKey)
if err != nil {
log.Println(errors.Wrapf(err, "Error decode Key: "))
}
Expand Down
5 changes: 3 additions & 2 deletions translit/translit.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ func EncodeTag(tag string) string {
}

func EncodeTitle(title string) string {
reg, err := regexp.Compile("[^a-zA-Z0-9а-яА-Я.]+")
reg, err := regexp.Compile("[^a-zA-Z0-9а-яА-Я.,]+")
if err != nil {
log.Fatal(err)
}
processedString := reg.ReplaceAllString(title, "-")
str, _ := encode(processedString)
s1, _ := encode(processedString)
str := strings.Replace(s1, ".", "", -1)
return str
}

Expand Down
7 changes: 7 additions & 0 deletions translit/translit_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ var encMap = map[string]string{
"ю": "yu",
"я": "ya",
" ": "-",
".": "",
",": "",
"(": "",
")": "",
"{": "",
"}": "",
"/": "",
}
2 changes: 1 addition & 1 deletion transports/websocket/object_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package websocket
import (
"time"

jsonrpc2websocket "github.com/asuleymanov/jsonrpc2/websocket"
"github.com/gorilla/websocket"
jsonrpc2websocket "github.com/sourcegraph/jsonrpc2/websocket"
)

// ObjectStream implements jsonrpc2.ObjectStream that uses a WebSocket.
Expand Down
2 changes: 1 addition & 1 deletion transports/websocket/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"time"

// Vendor
"github.com/asuleymanov/jsonrpc2"
"github.com/gorilla/websocket"
"github.com/pkg/errors"
"github.com/sourcegraph/jsonrpc2"
tomb "gopkg.in/tomb.v2"
)

Expand Down
10 changes: 9 additions & 1 deletion types/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ import (

type StringInt64Map map[string]int64

func (m StringInt64Map) MarshalJSON() ([]byte, error) {
/*func (m StringInt64Map) MarshalJSON() ([]byte, error) {
xs := make([]interface{}, len(m))
for k, v := range m {
xs = append(xs, []interface{}{k, v})
}
return json.Marshal(xs)
}*/

func (m StringInt64Map) MarshalJSON() ([]byte, error) {
xs := make([]interface{}, len(m))
for k, v := range m {
xs = append(xs, []interface{}{k, v})
}
return JSONMarshal(xs)
}

func (m *StringInt64Map) UnmarshalJSON(data []byte) error {
Expand Down
14 changes: 13 additions & 1 deletion types/operation_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (op *OperationObject) UnmarshalJSON(p []byte) error {
return nil
}

func (op *OperationObject) MarshalJSON() ([]byte, error) {
/*func (op *OperationObject) MarshalJSON() ([]byte, error) {
return json.Marshal(&rawOperationObject{
BlockNumber: op.BlockNumber,
TransactionID: op.TransactionID,
Expand All @@ -50,4 +50,16 @@ func (op *OperationObject) MarshalJSON() ([]byte, error) {
VirtualOperation: op.VirtualOperation,
Timestamp: op.Timestamp,
})
}*/

func (op *OperationObject) MarshalJSON() ([]byte, error) {
return JSONMarshal(&rawOperationObject{
BlockNumber: op.BlockNumber,
TransactionID: op.TransactionID,
TransactionInBlock: op.TransactionInBlock,
Operation: &operationTuple{op.Operation.Type(), op.Operation},
OperationInTransaction: op.OperationInTransaction,
VirtualOperation: op.VirtualOperation,
Timestamp: op.Timestamp,
})
}
32 changes: 27 additions & 5 deletions types/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ func (op *ConvertOperation) Data() interface{} {
// (exchange_rate) )

type FeedPublishOperation struct {
Publisher string `json:"publisher"`
ExchangeRate struct {
Base string `json:"base"`
Quote string `json:"quote"`
} `json:"exchange_rate"`
Publisher string `json:"publisher"`
ExchangeRate ExchRate `json:"exchange_rate"`
}

type ExchRate struct {
Base string `json:"base"`
Quote string `json:"quote"`
}

func (op *FeedPublishOperation) Type() OpType {
Expand All @@ -64,6 +66,15 @@ func (op *FeedPublishOperation) Data() interface{} {
return op
}

func (op *FeedPublishOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeTransfer.Code()))
enc.Encode(op.Publisher)
enc.EncodeMoney(op.ExchangeRate.Base)
enc.EncodeMoney(op.ExchangeRate.Quote)
return enc.Err()
}

// FC_REFLECT( steemit::chain::pow,
// (worker)
// (input)
Expand Down Expand Up @@ -520,6 +531,17 @@ func (op *WitnessUpdateOperation) Data() interface{} {
return op
}

func (op *WitnessUpdateOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeTransfer.Code()))
enc.Encode(op.Owner)
enc.Encode(op.Url)
enc.Encode(op.BlockSigningKey)
enc.Encode(op.Props)
enc.Encode(op.Fee)
return enc.Err()
}

type CustomOperation struct {
RequiredAuths []string `json:"required_auths"`
Id uint16 `json:"id"`
Expand Down

0 comments on commit 0be8864

Please sign in to comment.