// errors
var (
- ErrBadRefData = errors.New("transaction reference data does not match previous template's reference data")
- ErrBadTxInputIdx = errors.New("unsigned tx missing input")
+ //ErrBadRefData means invalid reference data
+ ErrBadRefData = errors.New("transaction reference data does not match previous template's reference data")
+ //ErrBadTxInputIdx means unsigned tx input
+ ErrBadTxInputIdx = errors.New("unsigned tx missing input")
+ //ErrBadWitnessComponent means invalid witness component
ErrBadWitnessComponent = errors.New("invalid witness component")
- ErrBadAmount = errors.New("bad asset amount")
- ErrBlankCheck = errors.New("unsafe transaction: leaves assets free to control")
- ErrAction = errors.New("errors occurred in one or more actions")
- ErrMissingFields = errors.New("required field is missing")
+ //ErrBadAmount means invalid asset amount
+ ErrBadAmount = errors.New("bad asset amount")
+ //ErrBlankCheck means unsafe transaction
+ ErrBlankCheck = errors.New("unsafe transaction: leaves assets free to control")
+ //ErrAction means errors occurred in actions
+ ErrAction = errors.New("errors occurred in one or more actions")
+ //ErrMissingFields means missing required fields
+ ErrMissingFields = errors.New("required field is missing")
)
// Build builds or adds on to a transaction.
return []byte(TxIndexPrefix + txID)
}
-//deleteTransaction delete transactions when orphan block rollback
+// deleteTransaction delete transactions when orphan block rollback
func (w *Wallet) deleteTransactions(batch db.Batch, height uint64) {
tmpTx := query.AnnotatedTx{}
for txIter.Next() {
if err := json.Unmarshal(txIter.Value(), &tmpTx); err == nil {
- //delete index
+ // delete index
batch.Delete(calcTxIndexKey(tmpTx.ID.String()))
}
}
}
-//ReverseAccountUTXOs process the invalid blocks when orphan block rollback
+// ReverseAccountUTXOs process the invalid blocks when orphan block rollback
func (w *Wallet) reverseAccountUTXOs(batch db.Batch, b *legacy.Block, txStatus *bc.TransactionStatus) {
var err error
- //unknow how many spent and retire outputs
+ // unknow how many spent and retire outputs
reverseOuts := make([]*rawOutput, 0)
- //handle spent UTXOs
+ // handle spent UTXOs
for txIndex, tx := range b.Transactions {
for _, inpID := range tx.Tx.InputIDs {
- //spend and retire
+ // spend and retire
sp, err := tx.Spend(inpID)
if err != nil {
continue
return
}
- //handle new UTXOs
+ // handle new UTXOs
for _, tx := range b.Transactions {
for j := range tx.Outputs {
resOutID := tx.ResultIds[j]
resOut, ok := tx.Entries[*resOutID].(*bc.Output)
if !ok {
- //retirement
+ // retirement
continue
}
}
}
-//save external and local assets definition,
-//when query ,query local first and if have no then query external
-//details see getAliasDefinition
+// saveExternalAssetDefinition save external and local assets definition,
+// when query ,query local first and if have no then query external
+// details see getAliasDefinition
func saveExternalAssetDefinition(b *legacy.Block, walletDB db.DB) {
storeBatch := walletDB.NewBatch()
defer storeBatch.Write()
}
}
-// Summary is ....
+// Summary is the struct of transaction's input and output summary
type Summary struct {
Type string `json:"type"`
AssetID bc.AssetID `json:"asset_id,omitempty"`
Arbitrary chainjson.HexBytes `json:"arbitrary,omitempty"`
}
-// TxSummary is ....
+// TxSummary is the struct of transaction summary
type TxSummary struct {
ID bc.Hash `json:"id"`
Timestamp time.Time `json:"timestamp"`
Outputs []Summary `json:"outputs"`
}
-//indexTransactions saves all annotated transactions to the database.
+// indexTransactions saves all annotated transactions to the database.
func (w *Wallet) indexTransactions(batch db.Batch, b *legacy.Block, txStatus *bc.TransactionStatus) error {
annotatedTxs := w.filterAccountTxs(b, txStatus)
saveExternalAssetDefinition(b, w.DB)
return nil
}
-//buildAccountUTXOs process valid blocks to build account unspent outputs db
+// buildAccountUTXOs process valid blocks to build account unspent outputs db
func (w *Wallet) buildAccountUTXOs(batch db.Batch, b *legacy.Block, txStatus *bc.TransactionStatus) {
// get the spent UTXOs and delete the UTXOs from DB
prevoutDBKeys(batch, b, txStatus)
- //handle new UTXOs
+ // handle new UTXOs
outs := make([]*rawOutput, 0, len(b.Transactions))
for txIndex, tx := range b.Transactions {
for j, out := range tx.Outputs {
refData: *resOut.Data,
}
- //coinbase utxo valid height
+ // coinbase utxo valid height
if txIndex == 0 {
out.ValidHeight = b.Height + consensus.CoinbasePendingBlockNumber
}
var hash [32]byte
for s := range outsByScript {
- //smart contract UTXO
+ // smart contract UTXO
if !segwit.IsP2WScript([]byte(s)) {
for _, out := range outsByScript[s] {
newOut := &accountOutput{
return nil
}
-// filt related and build the fully annotated transactions.
+// filterAccountTxs related and build the fully annotated transactions.
func (w *Wallet) filterAccountTxs(b *legacy.Block, txStatus *bc.TransactionStatus) []*query.AnnotatedTx {
annotatedTxs := make([]*query.AnnotatedTx, 0, len(b.Transactions))
for pos, tx := range b.Transactions {
return annotatedTxs
}
-//GetTransactionsByTxID get account txs by account tx ID
+// GetTransactionsByTxID get account txs by account tx ID
func (w *Wallet) GetTransactionsByTxID(txID string) ([]*query.AnnotatedTx, error) {
annotatedTxs := []*query.AnnotatedTx{}
formatKey := ""
return annotatedTxs, nil
}
-//GetTransactionsSummary get transactions summary
+// GetTransactionsSummary get transactions summary
func (w *Wallet) GetTransactionsSummary(transactions []*query.AnnotatedTx) []TxSummary {
Txs := make([]TxSummary, 0)
return false
}
-//GetTransactionsByAccountID get account txs by account ID
+// GetTransactionsByAccountID get account txs by account ID
func (w *Wallet) GetTransactionsByAccountID(accountID string) ([]*query.AnnotatedTx, error) {
annotatedTxs := []*query.AnnotatedTx{}
return annotatedTxs, nil
}
-//GetAccountUTXOs return all account unspent outputs
+// GetAccountUTXOs return all account unspent outputs
func (w *Wallet) GetAccountUTXOs(id string) ([]account.UTXO, error) {
accountUTXO := account.UTXO{}
accountUTXOs := make([]account.UTXO, 0)