Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix multi transfer kda #11

Merged
merged 1 commit into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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