diff --git a/client/functions.go b/client/functions.go index ed3d5b8..913227a 100644 --- a/client/functions.go +++ b/client/functions.go @@ -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 @@ -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 + } +} diff --git a/client/ident_wif.go b/client/ident_wif.go index 39c2cbc..32c6183 100644 --- a/client/ident_wif.go +++ b/client/ident_wif.go @@ -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: ")) } diff --git a/translit/translit.go b/translit/translit.go index fc3a58b..2d15139 100644 --- a/translit/translit.go +++ b/translit/translit.go @@ -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 } diff --git a/translit/translit_data.go b/translit/translit_data.go index b8701d9..5a671f4 100644 --- a/translit/translit_data.go +++ b/translit/translit_data.go @@ -39,4 +39,11 @@ var encMap = map[string]string{ "ю": "yu", "я": "ya", " ": "-", + ".": "", + ",": "", + "(": "", + ")": "", + "{": "", + "}": "", + "/": "", } diff --git a/transports/websocket/object_stream.go b/transports/websocket/object_stream.go index ba16a13..9c946ba 100644 --- a/transports/websocket/object_stream.go +++ b/transports/websocket/object_stream.go @@ -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. diff --git a/transports/websocket/transport.go b/transports/websocket/transport.go index c4e00ed..9a91337 100644 --- a/transports/websocket/transport.go +++ b/transports/websocket/transport.go @@ -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" ) diff --git a/types/map.go b/types/map.go index 35721cf..f135ed6 100644 --- a/types/map.go +++ b/types/map.go @@ -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 { diff --git a/types/operation_object.go b/types/operation_object.go index d3cfc47..080df24 100644 --- a/types/operation_object.go +++ b/types/operation_object.go @@ -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, @@ -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, + }) } diff --git a/types/operations.go b/types/operations.go index c5203c3..34ab30b 100644 --- a/types/operations.go +++ b/types/operations.go @@ -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 { @@ -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) @@ -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"`