SHARE
TWEET

Untitled

a guest Dec 10th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func (b *basicDecredService) CreateTransaction(ctx context.Context, address string, amount int64) (txHash string, err error) {
  2.     destination := &walletrpc.ConstructTransactionRequest_OutputDestination{
  3.         Address: address,
  4.     }
  5.  
  6.     nonChangeOutputs := []*walletrpc.ConstructTransactionRequest_Output{&walletrpc.ConstructTransactionRequest_Output{
  7.         Destination: destination,
  8.         Amount:      amount,
  9.     }}
  10.  
  11.     constTxRes, err := b.wsc.ConstructTransaction(ctx, &walletrpc.ConstructTransactionRequest{
  12.         SourceAccount:            uint32(AccountNumber),
  13.         RequiredConfirmations:    int32(TxRequiredConfirmations),
  14.         FeePerKb:                 int32(TxFeePerKb),
  15.         OutputSelectionAlgorithm: walletrpc.ConstructTransactionRequest_UNSPECIFIED,
  16.         NonChangeOutputs:         nonChangeOutputs,
  17.     })
  18.     if err != nil {
  19.         return "", err
  20.     }
  21.  
  22.     signTxRes, err := b.wsc.SignTransaction(ctx, &walletrpc.SignTransactionRequest{
  23.         Passphrase:            []byte(AccountPassphrase),
  24.         SerializedTransaction: constTxRes.UnsignedTransaction,
  25.     })
  26.     if err != nil {
  27.         return "", err
  28.     }
  29.  
  30.     pubTxRes, err := b.wsc.PublishTransaction(ctx, &walletrpc.PublishTransactionRequest{
  31.         SignedTransaction: signTxRes.Transaction,
  32.     })
  33.     if err != nil {
  34.         return "", err
  35.     }
  36.  
  37.     hash, err := chainhash.NewHash(pubTxRes.TransactionHash)
  38.     if err != nil {
  39.         return "", err
  40.     }
  41.     return hash.String(), err
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top