當前位置: 首頁>>代碼示例>>Golang>>正文


Golang interfaces.ITransaction類代碼示例

本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.ITransaction的典型用法代碼示例。如果您正苦於以下問題:Golang ITransaction類的具體用法?Golang ITransaction怎麽用?Golang ITransaction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ITransaction類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SignFactoidTransaction

func SignFactoidTransaction(n uint64, tx interfaces.ITransaction) {
	tx.AddAuthorization(NewFactoidRCDAddress(n))
	data, err := tx.MarshalBinarySig()
	if err != nil {
		panic(err)
	}

	sig := factoid.NewSingleSignatureBlock(NewPrivKey(n), data)

	//str, err := sig.JSONString()

	//fmt.Printf("sig, err - %v, %v\n", str, err)

	tx.SetSignatureBlock(0, sig)

	err = tx.Validate(1)
	if err != nil {
		panic(err)
	}

	err = tx.ValidateSignatures()
	if err != nil {
		panic(err)
	}
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:25,代碼來源:fBlock.go

示例2: MarshalTrans

func (b *FBlock) MarshalTrans() ([]byte, error) {
	var out bytes.Buffer
	var periodMark = 0
	var i int
	var trans interfaces.ITransaction
	for i, trans = range b.Transactions {

		for periodMark < len(b.endOfPeriod) &&
			b.endOfPeriod[periodMark] > 0 && // Ignore if markers are not set
			i == b.endOfPeriod[periodMark] {

			out.WriteByte(constants.MARKER)
			periodMark++
		}

		data, err := trans.MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
		if err != nil {
			return nil, err
		}
	}
	for periodMark < len(b.endOfPeriod) {
		out.WriteByte(constants.MARKER)
		periodMark++
	}
	return out.Bytes(), nil
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:30,代碼來源:fblock.go

示例3: AddECOutput

func (w *SCWallet) AddECOutput(trans interfaces.ITransaction, address interfaces.IAddress, amount uint64) error {

	_, adr, err := w.getWalletEntry([]byte(constants.W_RCD_ADDRESS_HASH), address)
	if err != nil {
		adr = address
	}

	trans.AddECOutput(CreateAddress(adr), amount)
	return nil
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:10,代碼來源:scwallet.go

示例4: Validate

// Returns an error message about what is wrong with the transaction if it is
// invalid, otherwise you are good to go.
func (fs *FactoidState) Validate(index int, trans interfaces.ITransaction) error {

	var sums = make(map[[32]byte]uint64, 10)  // Look at the sum of an address's inputs
	for _, input := range trans.GetInputs() { //    to a transaction.
		bal, err := factoid.ValidateAmounts(sums[input.GetAddress().Fixed()], input.GetAmount())
		if err != nil {
			return err
		}
		if int64(bal) > fs.State.GetF(true, input.GetAddress().Fixed()) {
			return fmt.Errorf("%s", "Not enough funds in input addresses for the transaction")
		}
		sums[input.GetAddress().Fixed()] = bal
	}

	return nil
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:18,代碼來源:factoidstate.go

示例5: ValidateTransactionAge

// Checks the transaction timestamp for validity in being included in the current
// No node has any responsiblity to forward on transactions that do not fall within
// the timeframe around a block defined by TRANSACTION_PRIOR_LIMIT and TRANSACTION_POST_LIMIT
func (fs *FactoidState) ValidateTransactionAge(trans interfaces.ITransaction) error {
	tsblk := fs.GetCurrentBlock().GetCoinbaseTimestamp()
	if tsblk < 0 {
		return fmt.Errorf("Block has no coinbase transaction at this time")
	}

	tstrans := int64(trans.GetMilliTimestamp())

	if tsblk-tstrans > constants.TRANSACTION_PRIOR_LIMIT {
		return fmt.Errorf("Transaction is too old to be included in the current block")
	}

	if tstrans-tsblk > constants.TRANSACTION_POST_LIMIT {
		return fmt.Errorf("Transaction is dated too far in the future to be included in the current block")
	}
	return nil
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:20,代碼來源:factoidstate.go

示例6: CheckSig

func (w RCD_1) CheckSig(trans interfaces.ITransaction, sigblk interfaces.ISignatureBlock) bool {
	if sigblk == nil {
		return false
	}
	data, err := trans.MarshalBinarySig()
	if err != nil {
		return false
	}
	signature := sigblk.GetSignature(0)
	if signature == nil {
		return false
	}
	cryptosig := signature.GetSignature()
	if cryptosig == nil {
		return false
	}

	return ed25519.VerifyCanonical(&w.PublicKey, data, cryptosig)
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:19,代碼來源:rcd1.go

示例7: UpdateInput

func (w *SCWallet) UpdateInput(trans interfaces.ITransaction, index int, address interfaces.IAddress, amount uint64) error {

	we, adr, err := w.getWalletEntry([]byte(constants.W_RCD_ADDRESS_HASH), address)
	if err != nil {
		return err
	}

	in, err := trans.GetInput(index)
	if err != nil {
		return err
	}

	trans.GetRCDs()[index] = we.GetRCD() // The RCD must match the (possibly) new input

	in.SetAddress(adr)
	in.SetAmount(amount)

	return nil
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:19,代碼來源:scwallet.go

示例8: MarshalTrans

func (b *FBlock) MarshalTrans() ([]byte, error) {
	var out primitives.Buffer
	var periodMark = 0
	var i int
	var trans interfaces.ITransaction

	// 	for _, v := range b.GetEndOfPeriod() {
	// 		if v == 0 {
	// 			return nil, fmt.Errorf("Factoid Block is incomplete.  Missing EOM markers detected: %v",b.endOfPeriod)
	// 		}
	// 	}

	for i, trans = range b.Transactions {

		for periodMark < len(b.endOfPeriod) &&
			b.endOfPeriod[periodMark] > 0 && // Ignore if markers are not set
			i == b.endOfPeriod[periodMark] {

			out.WriteByte(constants.MARKER)
			periodMark++
		}

		data, err := trans.MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
		if err != nil {
			return nil, err
		}
	}
	for periodMark < len(b.endOfPeriod) {
		out.WriteByte(constants.MARKER)
		periodMark++
	}
	return out.DeepCopyBytes(), nil
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:37,代碼來源:fblock.go

示例9: AddTransaction

// Only add valid transactions to the current
func (fs *FactoidState) AddTransaction(index int, trans interfaces.ITransaction) error {
	if err := fs.Validate(index, trans); err != nil {
		return err
	}
	if err := fs.ValidateTransactionAge(trans); err != nil {
		return err
	}
	if err := fs.UpdateTransaction(true, trans); err != nil {
		return err
	}
	if err := fs.CurrentBlock.AddTransaction(trans); err != nil {
		if err != nil {
			return err
		}
		// We assume validity has been done elsewhere.  We are maintaining the "seen" state of
		// all transactions here.
		fs.State.Replay.IsTSValid(constants.INTERNAL_REPLAY|constants.NETWORK_REPLAY, trans.GetSigHash(), trans.GetTimestamp())
		fs.State.Replay.IsTSValid(constants.NETWORK_REPLAY|constants.NETWORK_REPLAY, trans.GetSigHash(), trans.GetTimestamp())

		for index, eo := range trans.GetECOutputs() {
			pl := fs.State.ProcessLists.Get(fs.DBHeight)
			incBal := entryCreditBlock.NewIncreaseBalance()
			v := eo.GetAddress().Fixed()
			incBal.ECPubKey = (*primitives.ByteSlice32)(&v)
			incBal.NumEC = eo.GetAmount() / fs.GetCurrentBlock().GetExchRate()
			incBal.TXID = trans.GetSigHash()
			incBal.Index = uint64(index)
			entries := pl.EntryCreditBlock.GetEntries()
			i := 0
			// Find the end of the last IncreaseBalance in this minute
			for i < len(entries) {
				if _, ok := entries[i].(*entryCreditBlock.IncreaseBalance); ok {
					break
				}
				i++
			}
			entries = append(entries, nil)
			copy(entries[i+1:], entries[i:])
			entries[i] = incBal
			pl.EntryCreditBlock.GetBody().SetEntries(entries)
		}

	}

	return nil
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:47,代碼來源:factoidstate.go

示例10: AddInput

func (w *SCWallet) AddInput(trans interfaces.ITransaction, address interfaces.IAddress, amount uint64) error {
	// Check if this is an address we know.
	we, adr, err := w.getWalletEntry([]byte(constants.W_RCD_ADDRESS_HASH), address)
	// If it isn't, we assume the user knows what they are doing.
	if we == nil || err != nil {
		rcd := NewRCD_1(address.Bytes())
		trans.AddRCD(rcd)
		adr, err := rcd.GetAddress()
		if err != nil {
			return err
		}
		trans.AddInput(CreateAddress(adr), amount)
	} else {
		trans.AddRCD(we.GetRCD())
		trans.AddInput(CreateAddress(adr), amount)
	}

	return nil
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:19,代碼來源:scwallet.go

示例11: AddCoinbase

// Add the first transaction of a block.  This transaction makes the
// payout to the servers, so it has no inputs.   This transaction must
// be deterministic so that all servers will know and expect its output.
func (b *FBlock) AddCoinbase(trans interfaces.ITransaction) error {
	b.BodyMR = nil
	if len(b.Transactions) != 0 {
		return fmt.Errorf("The coinbase transaction must be the first transaction")
	}
	if len(trans.GetInputs()) != 0 {
		return fmt.Errorf("The coinbase transaction cannot have any inputs")
	}
	if len(trans.GetECOutputs()) != 0 {
		return fmt.Errorf("The coinbase transaction cannot buy Entry Credits")
	}
	if len(trans.GetRCDs()) != 0 {
		return fmt.Errorf("The coinbase transaction cannot have anyRCD blocks")
	}
	if len(trans.GetSignatureBlocks()) != 0 {
		return fmt.Errorf("The coinbase transaction is not signed")
	}

	// TODO Add check here for the proper payouts.

	b.Transactions = append(b.Transactions, trans)
	return nil
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:26,代碼來源:fblock.go

示例12: SignInputs

func (w *SCWallet) SignInputs(trans interfaces.ITransaction) (bool, error) {

	data, err := trans.MarshalBinarySig() // Get the part of the transaction we sign
	if err != nil {
		return false, err
	}

	var numSigs int = 0

	inputs := trans.GetInputs()
	rcds := trans.GetRCDs()
	for i, rcd := range rcds {
		rcd1, ok := rcd.(*RCD_1)
		if ok {
			pub := rcd1.GetPublicKey()
			wex, err := w.db.Get([]byte(constants.W_ADDRESS_PUB_KEY), pub, new(WalletEntry))
			if err != nil {
				return false, err
			}
			we := wex.(*WalletEntry)
			if we != nil {
				var pri [constants.SIGNATURE_LENGTH]byte
				copy(pri[:], we.private[0])
				bsig := ed25519.Sign(&pri, data)
				sig := new(FactoidSignature)
				sig.SetSignature(bsig[:])
				sigblk := new(SignatureBlock)
				sigblk.AddSignature(sig)
				trans.SetSignatureBlock(i, sigblk)
				numSigs += 1
			}
		}
	}

	return numSigs == len(inputs), nil
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:36,代碼來源:scwallet.go

示例13: UpdateTransaction

// Assumes validation has already been done.
func (fs *FactoidState) UpdateTransaction(rt bool, trans interfaces.ITransaction) error {
	for _, input := range trans.GetInputs() {
		adr := input.GetAddress().Fixed()
		oldv := fs.State.GetF(rt, adr)
		fs.State.PutF(rt, adr, oldv-int64(input.GetAmount()))
	}
	for _, output := range trans.GetOutputs() {
		adr := output.GetAddress().Fixed()
		oldv := fs.State.GetF(rt, adr)
		fs.State.PutF(rt, adr, oldv+int64(output.GetAmount()))
	}
	for _, ecOut := range trans.GetECOutputs() {
		ecbal := int64(ecOut.GetAmount()) / int64(fs.State.FactoshisPerEC)
		fs.State.PutE(rt, ecOut.GetAddress().Fixed(), fs.State.GetE(rt, ecOut.GetAddress().Fixed())+ecbal)
	}
	fs.State.NumTransactions++
	return nil
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:19,代碼來源:factoidstate.go

示例14: ValidateSignatures

func (w *SCWallet) ValidateSignatures(trans interfaces.ITransaction) error {
	if trans == nil {
		return fmt.Errorf("Missing Transaction")
	}
	return trans.ValidateSignatures()
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:6,代碼來源:scwallet.go

示例15: Validate

func (w *SCWallet) Validate(index int, trans interfaces.ITransaction) error {
	err := trans.Validate(index)
	return err
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:4,代碼來源:scwallet.go


注:本文中的github.com/FactomProject/factomd/common/interfaces.ITransaction類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。