Skip to content

Commit

Permalink
fix multi transfer kda
Browse files Browse the repository at this point in the history
  • Loading branch information
yurilozorio committed Mar 15, 2023
1 parent 1f5fb3d commit cf483e4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/demo/decode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func main() {
base := accounts[0].NewBaseTX()
tx, err := kc.MultiTransfer(
base,
"KLV",
[]models.ToAmount{{
ToAddress: accounts[1].Address().Bech32(),
Amount: 1000,
KDA: "KLV",
}})
if err != nil {
panic(err)
Expand Down
1 change: 1 addition & 0 deletions models/transactionAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type ToAmount struct {
ToAddress string
Amount float64
KDA string
}

type URI struct {
Expand Down
2 changes: 1 addition & 1 deletion provider/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type KleverChain interface {
GetMarshalizer() marshal.Marshalizer
// Transfer actions
Send(base *models.BaseTX, toAddr string, amount float64, kda string) (*proto.Transaction, error)
MultiTransfer(base *models.BaseTX, kda string, values []models.ToAmount) (*proto.Transaction, error)
MultiTransfer(base *models.BaseTX, values []models.ToAmount) (*proto.Transaction, error)
// Asset Actions
CreateKDA(base *models.BaseTX, kdaType proto.KDAData_EnumAssetType, op *models.KDAOptions) (*proto.Transaction, error)
AssetTrigger(base *models.BaseTX, kdaID string, triggerType AssetTriggerType, op *models.AssetTriggerOptions) (*proto.Transaction, error)
Expand Down
18 changes: 9 additions & 9 deletions provider/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ func (kc *kleverChain) getPrecision(kda string) (uint32, error) {
}

func (kc *kleverChain) Send(base *models.BaseTX, toAddr string, amount float64, kda string) (*proto.Transaction, error) {
values := []models.ToAmount{{ToAddress: toAddr, Amount: amount}}
values := []models.ToAmount{{ToAddress: toAddr, Amount: amount, KDA: kda}}

return kc.MultiTransfer(base, kda, values)
return kc.MultiTransfer(base, values)
}

func (kc *kleverChain) MultiTransfer(base *models.BaseTX, kda string, values []models.ToAmount) (*proto.Transaction, error) {
precision, err := kc.getPrecision(kda)
if err != nil {
return nil, err
}

func (kc *kleverChain) MultiTransfer(base *models.BaseTX, values []models.ToAmount) (*proto.Transaction, error) {
contracts := make([]interface{}, 0)
for _, to := range values {
precision, err := kc.getPrecision(to.KDA)
if err != nil {
return nil, err
}

parsedAmount := to.Amount * math.Pow10(int(precision))
contracts = append(contracts, models.TransferTXRequest{
Receiver: to.ToAddress,
Amount: int64(parsedAmount),
KDA: kda,
KDA: to.KDA,
})
}

Expand Down

0 comments on commit cf483e4

Please sign in to comment.