Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: add GetTransaction returning data for any transaction #2

Closed

Conversation

bjarnemagnussen
Copy link

No description provided.

Copy link

@sistemd sistemd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but all in all looks good

@@ -2359,6 +2359,149 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier,
return &res, err
}

// GetTransaction returns data if any transaction given its id. A mined
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// GetTransaction returns data if any transaction given its id. A mined
// GetTransaction returns data of any transaction given its id. A mined

@@ -2359,6 +2359,149 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier,
return &res, err
}

// GetTransaction returns data if any transaction given its id. A mined
// transaction is returned in a Block structure which records properties about
// the block. A bool is also returned to denote if the transaction did exist
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// the block. A bool is also returned to denote if the transaction did exist
// the block. A bool is also returned to denote if the transaction previously existed

Comment on lines +2419 to +2426
header, err := client.GetBlockHeaderVerbose(blockHash)
if err != nil {
return nil, false, err
}
blockHeight = header.Height
case *chain.BitcoindClient:
var err error
blockHeight, err = client.GetBlockHeight(blockHash)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird how you sometimes declare var err error upfront, and sometimes you use :=. I'd say to do either one or the other consistently instead of mixing the two. Not sure if LND has some convention here but I'd always use := unless I really need to create the variable without initializing it. (Such as before assigning it in both branches of an if or something).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually depends on if a return variable would otherwise overshadow a variable in the scope or not. In this case we are interested in the block height, which is directly returned for the BitcoindClient and therefore directly set to the variable blockHeight. But for the RPCClient instead we first have to declare a local return variable header with := that contains the height and then set the variable blockHeight in the scope to its Height value.

// database.
var summary *TransactionSummary
var inDB bool
err = walletdb.View(w.db, func(dbtx walletdb.ReadTx) error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this err is never checked? I suppose that is because rangeFn always returns nil. But in that case I'd use _ instead of assigning to err.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I should add it to the return statement!

// transaction is returned in a Block structure which records properties about
// the block. A bool is also returned to denote if the transaction did exist
// in the database or not.
func (w *Wallet) GetTransaction(txHash *chainhash.Hash) (*GetTransactionsResult,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Looking at the way you use this method from lnd-strike and also the fact that you always return either one mined or one unmined txn, I think this is not the most appropriate return type. We probably need a new type for this, maybe something like

type GetTransactionResult struct {
	MinedTransactions   *Block
	UnminedTransactions *TransactionSummary
}

And also we can document that at least one of the fields will be null. Possibly both if we can't find the txn.

Copy link
Author

@bjarnemagnussen bjarnemagnussen Nov 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I was a bit reluctant to do that as I thought this would involve changing the protobuf but we can simply declare the type above the function.

@bjarnemagnussen bjarnemagnussen deleted the feat/add-gettx-api branch November 11, 2021 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants