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

Commit

Permalink
Add Operation:
Browse files Browse the repository at this point in the history
LimitOrderCancel
LimitOrderCreate
Convert
TransferToVesting
WithdrawVesting
  • Loading branch information
asuleymanov committed Oct 11, 2017
1 parent 7791005 commit c6e938c
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 25 deletions.
4 changes: 2 additions & 2 deletions apis/database/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ func (api *API) GetWitnessByAccount(author string) (*Witness, error) {
//get_witnesses_by_vote
func (api *API) GetWitnessByVote(author string, limit uint) ([]*Witness, error) {
if limit > 1000 {
return nil, errors.New("GetOrderBook: limit must not exceed 1000")
return nil, errors.New("GetWitnessByVote: limit must not exceed 1000")
}
raw, err := api.Raw("get_witnesses_by_vote", []interface{}{author, limit})
if err != nil {
Expand All @@ -756,7 +756,7 @@ func (api *API) GetWitnessByVote(author string, limit uint) ([]*Witness, error)
//lookup_witness_accounts
func (api *API) LookupWitnessAccounts(author string, limit uint) ([]string, error) {
if limit > 1000 {
return nil, errors.New("GetOrderBook: limit must not exceed 1000")
return nil, errors.New("LookupWitnessAccounts: limit must not exceed 1000")
}
raw, err := api.Raw("lookup_witness_accounts", []interface{}{author, limit})
if err != nil {
Expand Down
87 changes: 68 additions & 19 deletions client/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,39 +519,88 @@ func (api *Client) Login(user_name, key string) bool {
}
}

func (api *Client) FeedPublish(username, base, quote string) error {
func (api *Client) LimitOrderCancel(owner string, orderid uint32) error {

ExchR := types.ExchRate{Base: base, Quote: quote}
tx := &types.FeedPublishOperation{
Publisher: username,
ExchangeRate: ExchR,
tx := &types.LimitOrderCancelOperation{
Owner: owner,
OrderID: orderid,
}

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

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

chprop := types.ChainProperties{AccountCreationFee: acfee, MaximumBlockSize: blocksize, SBDInterestRate: sbdir}
tx := &types.WitnessUpdateOperation{
Owner: username,
Url: url,
BlockSigningKey: signKey,
Props: &chprop,
Fee: fee,
expiration := time.Now().Add(3600000 * time.Second).UTC()
fok := false

tx := &types.LimitOrderCreateOperation{
Owner: owner,
OrderID: orderid,
AmountToSell: sell,
MinToReceive: buy,
FillOrKill: fok,
Expiration: &types.Time{&expiration},
}

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

func (api *Client) Convert(owner, amount string, requestid uint32) error {
tx := &types.ConvertOperation{
Owner: owner,
RequestID: requestid,
Amount: amount,
}

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

func (api *Client) TransferToVesting(from, to, amount string) error {
tx := &types.TransferToVestingOperation{
From: from,
To: to,
Amount: amount,
}

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

func (api *Client) WithdrawVesting(account, vshares string) error {
tx := &types.WithdrawVestingOperation{
Account: account,
VestingShares: vshares,
}

resp, err := api.Send_Trx(username, tx)
resp, err := api.Send_Trx(account, tx)
if err != nil {
return errors.Wrapf(err, "Error WitnessUpdate: ")
return errors.Wrapf(err, "Error WithdrawVesting: ")
} else {
log.Println("[WitnessUpdate] Block -> ", resp.BlockNum, " WitnessUpdate user -> ", username)
log.Println("[WithdrawVesting] Block -> ", resp.BlockNum, " WithdrawVesting user -> ", account)
return nil
}
}
6 changes: 3 additions & 3 deletions transactions/sign_the_shit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/sha256"
_ "encoding/hex"
"encoding/hex"
"errors"
"fmt"
//secp256k1 "github.com/btcsuite/btcd/btcec"
Expand All @@ -30,7 +30,7 @@ func (tx *SignedTransaction) Sign_Single(priv_b []byte, data []byte) []byte {

func signBuffer(buf []byte, private_key *ecdsa.PrivateKey) []byte {
//Debug info
//log.Println("signBuffer buf=", hex.EncodeToString(buf))
log.Println("signBuffer buf=", hex.EncodeToString(buf))
// Hash a message.
alg := sha256.New()
alg.Write(buf)
Expand All @@ -42,7 +42,7 @@ func signBuffer(buf []byte, private_key *ecdsa.PrivateKey) []byte {

func signBufferSha256(buf_sha256 []byte, private_key *ecdsa.PrivateKey) []byte { // *secp256k1.Signature
//Debug info
//log.Println("signBufferSha256 buf_sha256=", hex.EncodeToString(buf_sha256))
log.Println("signBufferSha256 buf_sha256=", hex.EncodeToString(buf_sha256))

var buf_sha256_clone = make([]byte, len(buf_sha256))
copy(buf_sha256_clone, buf_sha256)
Expand Down
57 changes: 56 additions & 1 deletion types/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ func (op *ConvertOperation) Data() interface{} {
return op
}

func (op *ConvertOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeConvert.Code()))
enc.Encode(op.Owner)
enc.Encode(op.RequestID)
enc.EncodeMoney(op.Amount)
return enc.Err()
}

// FC_REFLECT( steemit::chain::feed_publish_operation,
// (publisher)
// (exchange_rate) )
Expand Down Expand Up @@ -226,6 +235,15 @@ func (op *TransferToVestingOperation) Data() interface{} {
return op
}

func (op *TransferToVestingOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeTransferToVesting.Code()))
enc.Encode(op.From)
enc.Encode(op.To)
enc.EncodeMoney(op.Amount)
return enc.Err()
}

// FC_REFLECT( steemit::chain::withdraw_vesting_operation,
// (account)
// (vesting_shares) )
Expand All @@ -243,6 +261,14 @@ func (op *WithdrawVestingOperation) Data() interface{} {
return op
}

func (op *WithdrawVestingOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeWithdrawVesting.Code()))
enc.Encode(op.Account)
enc.EncodeMoney(op.VestingShares)
return enc.Err()
}

// FC_REFLECT( steemit::chain::set_withdraw_vesting_route_operation,
// (from_account)
// (to_account)
Expand Down Expand Up @@ -406,6 +432,18 @@ func (op *LimitOrderCreateOperation) Data() interface{} {
return op
}

func (op *LimitOrderCreateOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeLimitOrderCreate.Code()))
enc.Encode(op.Owner)
enc.Encode(op.OrderID)
enc.EncodeMoney(op.AmountToSell)
enc.EncodeMoney(op.MinToReceive)
enc.EncodeBool(op.FillOrKill)
enc.Encode(op.Expiration)
return enc.Err()
}

// FC_REFLECT( steemit::chain::limit_order_cancel_operation,
// (owner)
// (orderid) )
Expand All @@ -423,6 +461,14 @@ func (op *LimitOrderCancelOperation) Data() interface{} {
return op
}

func (op *LimitOrderCancelOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeLimitOrderCancel.Code()))
enc.Encode(op.Owner)
enc.Encode(op.OrderID)
return enc.Err()
}

// FC_REFLECT( steemit::chain::delete_comment_operation,
// (author)
// (permlink) )
Expand Down Expand Up @@ -616,7 +662,7 @@ func (op *ProveAuthorityOperation) Data() interface{} {
type RequestAccountRecoveryOperation struct {
RecoveryAccount string `json:"recovery_account"`
AccountToRecover string `json:"account_to_recover"`
NewOwnerAuthority string `json:"new_owner_authority"`
NewOwnerAuthority []interface{} `json:"new_owner_authority"`
Extensions []interface{} `json:"extensions"`
}

Expand Down Expand Up @@ -657,6 +703,15 @@ func (op *ChangeRecoveryAccountOperation) Data() interface{} {
return op
}

func (op *ChangeRecoveryAccountOperation) MarshalTransaction(encoder *transaction.Encoder) error {
enc := transaction.NewRollingEncoder(encoder)
enc.EncodeUVarint(uint64(TypeChangeRecoveryAccount.Code()))
enc.Encode(op.AccountToRecover)
enc.Encode(op.NewRecoveryAccount)
enc.Encode(byte(0))
return enc.Err()
}

type EscrowTransferOperation struct {
From string `json:"from"`
To string `json:"to"`
Expand Down

0 comments on commit c6e938c

Please sign in to comment.