本文整理汇总了Golang中github.com/skycoin/skycoin/src/coin.Transaction.Sigs方法的典型用法代码示例。如果您正苦于以下问题:Golang Transaction.Sigs方法的具体用法?Golang Transaction.Sigs怎么用?Golang Transaction.Sigs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skycoin/skycoin/src/coin.Transaction
的用法示例。
在下文中一共展示了Transaction.Sigs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InitTransaction
func InitTransaction() coin.Transaction {
var tx coin.Transaction
output := cipher.MustSHA256FromHex("043836eb6f29aaeb8b9bfce847e07c159c72b25ae17d291f32125e7f1912e2a0")
tx.PushInput(output)
for i := 0; i < 100; i++ {
addr := cipher.MustDecodeBase58Address(AddrList[i])
tx.PushOutput(addr, 1e12, 1) // 10e6*10e6
}
/*
seckeys := make([]cipher.SecKey, 1)
seckey := ""
seckeys[0] = cipher.MustSecKeyFromHex(seckey)
tx.SignInputs(seckeys)
*/
txs := make([]cipher.Sig, 1)
sig := "ed9bd7a31fe30b9e2d53b35154233dfdf48aaaceb694a07142f84cdf4f5263d21b723f631817ae1c1f735bea13f0ff2a816e24a53ccb92afae685fdfc06724de01"
txs[0] = cipher.MustSigFromHex(sig)
tx.Sigs = txs
tx.UpdateHeader()
err := tx.Verify()
if err != nil {
log.Panic(err)
}
log.Printf("signature= %s", tx.Sigs[0].Hex())
return tx
}
示例2: TransactionFromJSON
func TransactionFromJSON(str string) (coin.Transaction, error) {
var TxIn TransactionJSON
err := json.Unmarshal([]byte(str), TxIn)
if err != nil {
errors.New("cannot deserialize")
}
var tx coin.Transaction
tx.Sigs = make([]cipher.Sig, len(TxIn.Sigs))
tx.In = make([]cipher.SHA256, len(TxIn.In))
tx.Out = make([]coin.TransactionOutput, len(TxIn.Out))
for i, _ := range tx.Sigs {
sig2, err := cipher.SigFromHex(TxIn.Sigs[i])
if err != nil {
return coin.Transaction{}, errors.New("invalid signature")
}
tx.Sigs[i] = sig2
}
for i, _ := range tx.In {
hash, err := cipher.SHA256FromHex(TxIn.In[i])
if err != nil {
return coin.Transaction{}, errors.New("invalid signature")
}
tx.In[i] = hash
}
for i, _ := range tx.Out {
out, err := TransactionOutputFromJSON(TxIn.Out[i])
if err != nil {
return coin.Transaction{}, errors.New("invalid output")
}
tx.Out[i] = out
}
tx.Length = uint32(tx.Size())
tx.Type = 0
hash, err := cipher.SHA256FromHex(TxIn.Hash)
if err != nil {
return coin.Transaction{}, errors.New("invalid hash")
}
if hash != tx.Hash() {
}
InnerHash, err := cipher.SHA256FromHex(TxIn.Hash)
if InnerHash != tx.InnerHash {
return coin.Transaction{}, errors.New("inner hash")
}
err = tx.Verify()
if err != nil {
return coin.Transaction{}, errors.New("transaction failed verification")
}
return tx, nil
}