• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang xdr.Transaction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/stellar/go-stellar-base/xdr.Transaction的典型用法代码示例。如果您正苦于以下问题:Golang Transaction类的具体用法?Golang Transaction怎么用?Golang Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Transaction类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: MutateTransaction

// MutateTransaction for PaymentBuilder causes the underylying PaymentOp
// to be added to the operation list for the provided transaction
func (m PaymentBuilder) MutateTransaction(o *xdr.Transaction) error {
	if m.Err != nil {
		return m.Err
	}

	m.O.Body = xdr.NewOperationBodyPayment(m.P)
	o.Operations = append(o.Operations, m.O)
	return nil
}
开发者ID:jacksonh,项目名称:go-horizon,代码行数:11,代码来源:transaction.go


示例2: SignAndSubmitRawTransaction

// SignAndSubmitRawTransaction will:
// - update sequence number of the transaction to the current one,
// - sign it,
// - submit it to the network.
func (ts *TransactionSubmitter) SignAndSubmitRawTransaction(seed string, tx *xdr.Transaction) (response horizon.SubmitTransactionResponse, err error) {
	account, err := ts.GetAccount(seed)
	if err != nil {
		return
	}

	account.Mutex.Lock()
	account.SequenceNumber++
	tx.SeqNum = xdr.SequenceNumber(account.SequenceNumber)
	account.Mutex.Unlock()

	hash, err := TransactionHash(tx, ts.Network.Passphrase)
	if err != nil {
		ts.log.Print("Error calculating transaction hash")
		return
	}

	sig, err := account.Keypair.SignDecorated(hash[:])
	if err != nil {
		ts.log.Print("Error signing a transaction")
		return
	}

	envelopeXdr := xdr.TransactionEnvelope{
		Tx:         *tx,
		Signatures: []xdr.DecoratedSignature{sig},
	}

	txeB64, err := xdr.MarshalBase64(envelopeXdr)
	if err != nil {
		ts.log.Print("Cannot encode transaction envelope")
		return
	}

	transactionHashBytes, err := TransactionHash(tx, ts.Network.Passphrase)
	if err != nil {
		ts.log.WithFields(logrus.Fields{"err": err}).Warn("Error calculating tx hash")
		return
	}

	sentTransaction := &entities.SentTransaction{
		TransactionID: hex.EncodeToString(transactionHashBytes[:]),
		Status:        entities.SentTransactionStatusSending,
		Source:        account.Keypair.Address(),
		SubmittedAt:   ts.now(),
		EnvelopeXdr:   txeB64,
	}
	err = ts.EntityManager.Persist(sentTransaction)
	if err != nil {
		return
	}

	response, err = ts.Horizon.SubmitTransaction(txeB64)
	if err != nil {
		ts.log.Error("Error submitting transaction ", err)
		return
	}

	if response.Ledger != nil {
		sentTransaction.MarkSucceeded(*response.Ledger)
	} else {
		var result string
		if response.Extras != nil {
			result = response.Extras.ResultXdr
		} else {
			result = "<empty>"
		}
		sentTransaction.MarkFailed(result)
	}
	err = ts.EntityManager.Persist(sentTransaction)
	if err != nil {
		return
	}

	// Sync sequence number
	if response.Extras != nil && response.Extras.ResultXdr == "AAAAAAAAAAD////7AAAAAA==" {
		account.Mutex.Lock()
		ts.log.Print("Syncing sequence number for ", account.Keypair.Address())
		accountResponse, err2 := ts.Horizon.LoadAccount(account.Keypair.Address())
		if err2 != nil {
			ts.log.Error("Error updating sequence number ", err)
		} else {
			account.SequenceNumber, _ = strconv.ParseUint(accountResponse.SequenceNumber, 10, 64)
		}
		account.Mutex.Unlock()
	}
	return
}
开发者ID:FihlaTV,项目名称:bridge-server,代码行数:92,代码来源:transaction_submitter.go


示例3: MutateTransaction

// MutateTransaction for SourceAccount sets the transaction's SourceAccount
// to the pubilic key for the address provided
func (m Defaults) MutateTransaction(o *xdr.Transaction) error {
	o.Fee = 10
	memo, err := xdr.NewMemo(xdr.MemoTypeMemoNone, nil)
	o.Memo = memo
	return err
}
开发者ID:lackac,项目名称:horizon,代码行数:8,代码来源:transaction.go



注:本文中的github.com/stellar/go-stellar-base/xdr.Transaction类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.Wrap函数代码示例发布时间:2022-05-28
下一篇:
Golang xdr.Asset类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap