The backend for the project formerly known as signet, now known as beignet.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

57 wiersze
1.4 KiB

  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/imosed/signet/client"
  5. "github.com/rs/zerolog/log"
  6. "github.com/stellar/go/clients/horizonclient"
  7. "github.com/stellar/go/keypair"
  8. "github.com/stellar/go/network"
  9. "github.com/stellar/go/protocols/horizon"
  10. "github.com/stellar/go/txnbuild"
  11. )
  12. func SendAsset(from *keypair.Full, memo txnbuild.Memo, operations []txnbuild.Operation) (bool, error) {
  13. var err error
  14. source := keypair.MustParseFull(from.Seed())
  15. sourceReq := horizonclient.AccountRequest{AccountID: source.Address()}
  16. var sourceAcct horizon.Account
  17. sourceAcct, err = client.SignetClient.AccountDetail(sourceReq)
  18. if err != nil {
  19. return false, err
  20. }
  21. tx, err := txnbuild.NewTransaction(
  22. txnbuild.TransactionParams{
  23. SourceAccount: &sourceAcct,
  24. IncrementSequenceNum: true,
  25. Operations: operations,
  26. BaseFee: txnbuild.MinBaseFee,
  27. Memo: memo,
  28. Preconditions: txnbuild.Preconditions{
  29. TimeBounds: txnbuild.NewTimeout(15),
  30. },
  31. })
  32. if err != nil {
  33. return false, err
  34. }
  35. tx, err = tx.Sign(network.TestNetworkPassphrase, source)
  36. if err != nil {
  37. return false, err
  38. }
  39. var response horizon.Transaction
  40. response, err = client.SignetClient.SubmitTransaction(tx)
  41. if err != nil {
  42. return false, err
  43. }
  44. log.Info().Msg(fmt.Sprintf("Successful Transaction: { Ledger: %d, Hash: %s }", response.Ledger, response.Hash))
  45. return true, nil
  46. }