Skip to content

Commit

Permalink
fix SigToTransaction payer bug (#28)
Browse files Browse the repository at this point in the history
* fix typo

* add NewMultiTransferTransaction
fix SignToTransaction payer bug
  • Loading branch information
gasby88 authored Jul 17, 2018
1 parent 3986b4f commit f549608
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
16 changes: 9 additions & 7 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,22 @@ func NewInvokeTransaction(gasPrice, gasLimit uint64, code []byte) *types.Transac

//Sign to a transaction
func SignToTransaction(tx *types.Transaction, signer *account.Account) error {
tx.Payer = signer.Address
if tx.Payer == common.ADDRESS_EMPTY {
tx.Payer = signer.Address
}
txHash := tx.Hash()
sigData, err := SignToData(txHash.ToArray(), signer)
if err != nil {
return fmt.Errorf("SignToData error:%s", err)
}
sig := &types.Sig{
if tx.Sigs == nil {
tx.Sigs = make([]*types.Sig, 0)
}
tx.Sigs = append(tx.Sigs, &types.Sig{
PubKeys: []keypair.PublicKey{signer.PublicKey},
M: 1,
SigData: [][]byte{sigData},
}
tx.Sigs = []*types.Sig{sig}

})
return nil
}

Expand All @@ -92,8 +95,7 @@ func MultiSignToTransaction(tx *types.Transaction, m uint16, pubKeys []keypair.P
if !validPubKey {
return fmt.Errorf("Invalid signer")
}
var emptyAddress = common.Address{}
if tx.Payer == emptyAddress {
if tx.Payer == common.ADDRESS_EMPTY {
payer, err := types.AddressFromMultiPubKeys(pubKeys, int(m))
if err != nil {
return fmt.Errorf("AddressFromMultiPubKeys error:%s", err)
Expand Down
4 changes: 4 additions & 0 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ func (this *RpcClient) NewTransferTransaction(gasPrice, gasLimit uint64,
return utils.NewTransferTransaction(gasPrice, gasLimit, asset, from, to, amount)
}

func (this *RpcClient) NewMultiTransferTransfer(gasPrice, gasLimit uint64, asset string, states []*ont.State) (*types.Transaction, error) {
return utils.NewMultiTransferTransaction(gasPrice, gasLimit, asset, states)
}

func (this *RpcClient) NewApproveTransaction(gasPrice, gasLimit uint64,
asset string, from, to common.Address,
amount uint64) (*types.Transaction, error) {
Expand Down
14 changes: 9 additions & 5 deletions utils/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,21 @@ func NewNeoVMSInvokeTransaction(
}

func NewTransferTransaction(gasPrice, gasLimit uint64, asset string, from, to common.Address, amount uint64) (*types.Transaction, error) {
contractAddress, err := GetAssetAddress(asset)
if err != nil {
return nil, err
}
var sts []*ont.State
sts = append(sts, &ont.State{
From: from,
To: to,
Value: amount,
})
return NewNativeInvokeTransaction(gasPrice, gasLimit, sdkcom.VERSION_CONTRACT_ONT, contractAddress, sdkcom.NATIVE_TRANSFER, []interface{}{sts})
return NewMultiTransferTransaction(gasPrice, gasLimit, asset, sts)
}

func NewMultiTransferTransaction(gasPrice, gasLimit uint64, asset string, states []*ont.State) (*types.Transaction, error) {
contractAddress, err := GetAssetAddress(asset)
if err != nil {
return nil, err
}
return NewNativeInvokeTransaction(gasPrice, gasLimit, sdkcom.VERSION_CONTRACT_ONT, contractAddress, sdkcom.NATIVE_TRANSFER, []interface{}{states})
}

func NewApproveTransaction(gasPrice, gasLimit uint64, asset string, from, to common.Address, amount uint64) (*types.Transaction, error) {
Expand Down

0 comments on commit f549608

Please sign in to comment.