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

Commit

Permalink
Add OpType into OperationObject
Browse files Browse the repository at this point in the history
  • Loading branch information
asuleymanov committed Oct 2, 2017
1 parent 0be8864 commit 0197e17
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
21 changes: 21 additions & 0 deletions apis/database/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,27 @@ func (api *API) GetAccountHistory(account string, from uint64, limit uint32) (*j
return api.Raw("get_account_history", []interface{}{account, from, limit})
}

/*func (api *API) GetAccountHistory(account string, from uint64, limit uint32) ([]*AccountHistory, error) {
raw, err := api.Raw("get_account_history", []interface{}{account, from, limit})
if err != nil {
return nil, err
}
var tmp1 [][]interface{}
if err := json.Unmarshal([]byte(*raw), &tmp1); err != nil {
return nil, err
}
var resp []*AccountHistory
for _, v := range tmp1 {
byteData, _ := json.Marshal(v[1])
var tmp AccountHistory
if err := json.Unmarshal(byteData, &tmp); err != nil {
return nil, err
}
resp = append(resp, &tmp)
}
return resp, nil
}*/

//get_owner_history
func (api *API) GetOwnerHistory(accountName string) (*json.RawMessage, error) {
return api.Raw("get_owner_history", []interface{}{accountName})
Expand Down
10 changes: 10 additions & 0 deletions apis/database/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,13 @@ type Categories struct {
Discussions *types.Int `json:"discussions"`
LastUpdate string `json:"last_update"`
}

type AccountHistory struct {
TrxID string `json:"trx_id"`
Block int `json:"block"`
TrxInBlock int `json:"trx_in_block"`
OpInTrx int `json:"op_in_trx"`
VirtualOp int `json:"virtual_op"`
Timestamp string `json:"timestamp"`
Op []interface{} `json:"op"`
}
6 changes: 3 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type BResp struct {
Expired bool
}

func initclient(url string) *rpc.Client {
func initclient(url []string) *rpc.Client {
// Инициализация Websocket
t, err := websocket.NewTransport([]string{url})
t, err := websocket.NewTransport(url)
if err != nil {
panic(errors.Wrapf(err, "Error Websocket: "))
}
Expand All @@ -62,7 +62,7 @@ func initChainId(str string) *transactions.Chain {
return &ChainId
}

func NewApi(url, chain string) *Client {
func NewApi(url []string, chain string) *Client {
return &Client{
Rpc: initclient(url),
Chain: initChainId(chain),
Expand Down
4 changes: 2 additions & 2 deletions client/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (api *Client) Transfer(from_name, to_name, memo, ammount string) error {
}
}

func (api *Client) Login(user_name, pass string) bool {
func (api *Client) Login(user_name, key string) bool {
json_string := "[\"login\",{\"account\":\"" + user_name + "\",\"app\":\"golos-go(go-steem)\"}]"

strx := &types.CustomJSONOperation{
Expand Down Expand Up @@ -450,7 +450,7 @@ func (api *Client) Login(user_name, pass string) bool {

// Получаем необходимый для подписи ключ
var keys [][]byte
privKey, _ := wif.Decode(string([]byte(pass)))
privKey, _ := wif.Decode(string([]byte(key)))
keys = append(keys, privKey)

// Подписываем транзакцию
Expand Down
2 changes: 2 additions & 0 deletions types/operation_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type OperationObject struct {
TransactionID string `json:"trx_id"`
TransactionInBlock uint32 `json:"trx_in_block"`
Operation Operation `json:"op"`
OperationType OpType `json:"-"`
OperationInTransaction uint16 `json:"op_in_trx"`
VirtualOperation uint64 `json:"virtual_op"`
Timestamp *Time `json:"timestamp"`
Expand All @@ -34,6 +35,7 @@ func (op *OperationObject) UnmarshalJSON(p []byte) error {
op.TransactionID = raw.TransactionID
op.TransactionInBlock = raw.TransactionInBlock
op.Operation = raw.Operation.Data
op.OperationType = raw.Operation.Type
op.OperationInTransaction = raw.OperationInTransaction
op.VirtualOperation = raw.VirtualOperation
op.Timestamp = raw.Timestamp
Expand Down
30 changes: 14 additions & 16 deletions types/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func (op *FeedPublishOperation) MarshalTransaction(encoder *transaction.Encoder)
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeTransfer.Code()))
enc.Encode(op.Publisher)
enc.EncodeMoney(op.ExchangeRate.Base)
enc.EncodeMoney(op.ExchangeRate.Quote)
enc.EncodeMoney(op.ExchangeRate.Base)
return enc.Err()
}

Expand Down Expand Up @@ -249,13 +249,6 @@ func (op *WithdrawVestingOperation) Data() interface{} {
// (percent)
// (auto_vest) )

// FC_REFLECT( steemit::chain::witness_update_operation,
// (owner)
// (url)
// (block_signing_key)
// (props)
// (fee) )

// FC_REFLECT( steemit::chain::account_witness_vote_operation,
// (account)
// (witness)(approve) )
Expand Down Expand Up @@ -514,7 +507,12 @@ func (op *UnknownOperation) Data() interface{} {
return op.data
}

// test
// FC_REFLECT( steemit::chain::witness_update_operation,
// (owner)
// (url)
// (block_signing_key)
// (props)
// (fee) )
type WitnessUpdateOperation struct {
Owner string `json:"owner"`
Url string `json:"url"`
Expand Down Expand Up @@ -572,12 +570,12 @@ func (op *SetWithdrawVestingRouteOperation) Data() interface{} {
}

type LimitOrderCreate2Operation struct {
Qwner string `json:"owner"`
Orderid uint32 `json:"orderid"`
AmountToSell string `json:"amount_to_sell"`
ExchangeRate string `json:"exchange_rate"`
FillOrKill bool `json:"fill_or_kill"`
Expiration uint32 `json:"expiration"`
Qwner string `json:"owner"`
Orderid uint32 `json:"orderid"`
AmountToSell string `json:"amount_to_sell"`
ExchangeRate ExchRate `json:"exchange_rate"`
FillOrKill bool `json:"fill_or_kill"`
Expiration uint32 `json:"expiration"`
}

func (op *LimitOrderCreate2Operation) Type() OpType {
Expand Down Expand Up @@ -771,7 +769,7 @@ func (op *TransferToSavingsOperation) MarshalTransaction(encoder *transaction.En
enc.EncodeUVarint(uint64(TypeTransferToSavings.Code()))
enc.Encode(op.From)
enc.Encode(op.To)
enc.Encode(op.Amount)
enc.EncodeMoney(op.Amount)
enc.Encode(op.Memo)
return enc.Err()
}
Expand Down

0 comments on commit 0197e17

Please sign in to comment.