2021-01-26 10:21:16 +00:00
|
|
|
package balance
|
|
|
|
|
|
|
|
import (
|
2024-10-21 13:27:28 +00:00
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2021-01-26 10:21:16 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 09:24:25 +00:00
|
|
|
// TransferPrm groups parameters of TransferX method.
|
|
|
|
type TransferPrm struct {
|
|
|
|
Amount int64
|
2021-01-26 10:21:16 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
From, To user.ID
|
2021-01-26 10:21:16 +00:00
|
|
|
|
2022-01-31 09:24:25 +00:00
|
|
|
Details []byte
|
2021-11-14 22:04:19 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
2021-01-26 10:21:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 09:24:25 +00:00
|
|
|
// TransferX transfers p.Amount of GASe-12 from p.From to p.To
|
|
|
|
// with details p.Details through direct smart contract call.
|
|
|
|
//
|
|
|
|
// If TryNotary is provided, calls notary contract.
|
2024-10-21 13:27:28 +00:00
|
|
|
func (c *Client) TransferX(ctx context.Context, p TransferPrm) error {
|
2024-12-04 10:19:37 +00:00
|
|
|
from, err := p.From.ScriptHash()
|
2022-01-31 09:24:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-26 10:21:16 +00:00
|
|
|
|
2024-12-04 10:19:37 +00:00
|
|
|
to, err := p.To.ScriptHash()
|
2022-01-31 09:24:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-26 10:21:16 +00:00
|
|
|
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(transferXMethod)
|
2022-03-31 08:08:27 +00:00
|
|
|
prm.SetArgs(from, to, p.Amount, p.Details)
|
2022-01-31 09:24:25 +00:00
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
_, err = c.client.Invoke(ctx, prm)
|
2021-05-18 08:12:51 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", transferXMethod, err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
|
|
|
return nil
|
2021-01-26 10:21:16 +00:00
|
|
|
}
|