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

multi: Allow trezor ticket purchasing on testnet. #2869

Closed
wants to merge 1 commit into from

Conversation

JoeGruffins
Copy link
Member

@JoeGruffins JoeGruffins commented Nov 6, 2020

Fix updating firmware with model T by sending binary rather than hex.

In signTransactionAttemptTrezor give spending from stake scripts
inputs specific script types "SPENDSSRTX" and "SPENDSSGEN" rather than
"SPENDADDRESS" as trezor needs this information to process the scripts.

Add purchaseTicketsV3 which purchases tickets using a watching only
trezor wallet from a vsp with api v3. Errors if not on testnet.

Add separate payVSPFee function that will pay a tickets fee if not
already paid, and throws if already paid.

Correct purchase ticket button for watching only wallets. It no longer
asks for a password. Connect purchasing through trezor when isTrezor is
true.

Add vsp v3 endpoints "feeaddress" and "payfee" to allowed external
requests.

Change wallet/control.js to not require an unlocked wallet when signTx
is false.

@JoeGruffins JoeGruffins force-pushed the trezorstake branch 2 times, most recently from 21ae598 to b74dddb Compare November 18, 2020 03:50
@JoeGruffins JoeGruffins changed the title multi: Allow ticket purchasing on trezor on testnet. multi: Allow trezor ticket purchasing on testnet. Nov 18, 2020
Copy link
Member Author

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

Lots of TODO's but hopefully that's ok. This pr only means to get the ball rolling on testnet.

await signTransactionAttemptTrezor(splitTx, changeIndex)(dispatch, getState);
const refTxs = await walletTxToRefTx(walletService, decodedInp);

for (const ticket of res.getTicketsList()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Even when specifying number of tickets as more, this only returns one ticket. Am I doing it wrong?

app/actions/TrezorActions.js Outdated Show resolved Hide resolved
Comment on lines 944 to 1017
// TODO: Fill this with deterministic crypto magic.
const privateKeySeed = Buffer.alloc(32);
privateKeySeed[31] = 1;
const net = conToTrezCoinParams(chainParams.trezorCoinName);
const ecp = ECPair.fromPrivateKeyBuffer(privateKeySeed, net);
const votingKey = ecp.toWIF();
const votingAddr = ecp.getAddress();
Copy link
Member Author

Choose a reason for hiding this comment

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

This will need to be changed but hopefully ok for now.

app/actions/TrezorActions.js Show resolved Hide resolved
// payVSPFee attempts to contact a vst about a ticket and pay the fee if
// necessary. It will search transacitons for a suitable fee transaction before
// attempting to pay if newTicket is false.
async function payVSPFee(host, txHex, votingKey, accountNum, newTicket, dispatch, getState) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This will need to be callable from somewhere else eventually. Will need to know the host though, and I'm not where to save that info. I suppose the user can choose per ticket where they think it came from if they still need to pay the fee for some reason. This will require ui changes which I am not comfortable doing in this pr...

// findFeeTx searches unmined and recent transactions for a tx that pays to
// FeeAddr of the amount feeAmt. It stops searching below a resonable depth for
// a ticket.
async function findFeeTx(feeAddr, feeAmt, dispatch, getState) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This looks to work well, but if there's a better way please tell me.

app/main_dev/ipc.js Outdated Show resolved Hide resolved
@JoeGruffins
Copy link
Member Author

JoeGruffins commented Nov 18, 2020

This pr should be used with trezor core firmware trezor/trezor-firmware#1249

@JoeGruffins JoeGruffins marked this pull request as ready for review November 18, 2020 04:47
@JoeGruffins
Copy link
Member Author

JoeGruffins commented Nov 19, 2020

Two more gotchas I forgot to mention:

  1. The wallet must be in spv mode. edit: Fixed by @matheusd
  2. You must give the wallet some time to get ready after opening to attempt a purchase. Otherwise the grpc call hangs.

These are both problems that must be fixed at some point.

@JoeGruffins
Copy link
Member Author

Another "insufficient funds" issue has been popping up. No idea of the cause right now, but it can be temporary solved by sending a normal transaction to yourself.

for (let i = 0; i < decodedInp.outputs.length; i++) {
changeIndexes.push(i);
};
await signTransactionAttemptTrezor(splitTx, changeIndexes)(dispatch, getState);
Copy link
Member Author

Choose a reason for hiding this comment

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

Cancelling this on trezor doesn't stop the purchase but it should.

// payVSPFee attempts to contact a vst about a ticket and pay the fee if
// necessary. It will search transacitons for a suitable fee transaction before
// attempting to pay if newTicket is false.
async function payVSPFee(host, txHex, votingKey, accountNum, newTicket, dispatch, getState) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Should probably move these functions to helpers.

const {
grpc: { votingService }
} = getState();
const voteChoicesRes = await wallet.getVoteChoices(votingService);
Copy link
Member Author

Choose a reason for hiding this comment

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

I assume this is fetching the default.

Copy link
Member

@matheusd matheusd left a comment

Choose a reason for hiding this comment

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

Please just drop the binary files and I'll merge this.

Commented on the wrong PR, sorry.

@JoeGruffins
Copy link
Member Author

Should I be worried about these test failures?

@matheusd
Copy link
Member

Have you rebased to latest master yet? That might fix it.

@amass01
Copy link
Member

amass01 commented Mar 26, 2021

Something is off with the CI, looking into it...

@JoeGruffins
Copy link
Member Author

JoeGruffins commented Mar 26, 2021

Have you rebased to latest master yet? That might fix it.

Yes. I also tried the tests locally, on master, and had some fail. Not sure if there is something to do besides yarn run though.

Will do another rebase though, as there are some conflicts now.

@amass01
Copy link
Member

amass01 commented Mar 26, 2021

Will do another rebase though, as there are some conflicts now.

Latest master might resolve the CI troubles.

@JoeGruffins
Copy link
Member Author

This looks like an expected test failure, will fix.

@JoeGruffins
Copy link
Member Author

JoeGruffins commented Jun 8, 2021

@matheusd please advise if 96c8c3e is the right way to handle this. Also, not sure about the build failure. It's working locally.

edit: nevermind. I removed the dependency.

@JoeGruffins JoeGruffins force-pushed the trezorstake branch 3 times, most recently from c3f2f8c to 2609d15 Compare June 10, 2021 10:23
Copy link
Member

@matheusd matheusd left a comment

Choose a reason for hiding this comment

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

Purchasing worked on the latest stable version of the model T emulator (2.4.0). Woop! 🎉

app/helpers/msgTx.js Outdated Show resolved Hide resolved
app/actions/TrezorActions.js Outdated Show resolved Hide resolved
app/actions/TrezorActions.js Show resolved Hide resolved
app/actions/TrezorActions.js Outdated Show resolved Hide resolved
@JoeGruffins
Copy link
Member Author

JoeGruffins commented Jul 7, 2021

Getting an error like

Access to fetch at 'https://testnet-vsp.jholdstock.uk/api/v3/feeaddress' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

suddenly. looking into it...

f448243 did something

It looks like tweaking some nginx fields on the server has fixed it.

@JoeGruffins
Copy link
Member Author

The values added to the header seem to be necessary for CORS and the diff was supplied by @matheusd

Add purchaseTicketsV3 which purchases tickets using a watching only
trezor wallet from a vsp with api v3. Errors if not on testnet.

Add separate payVSPFee function that will pay a tickets fee if not
already paid, and throws if already paid.

Correct purchase ticket button for watching only wallets. It no longer
asks for a password. Connect purchasing through trezor when isTrezor is
true.

Add vsp v3 endpoints "feeaddress" and "payfee" to allowed external
requests.

Change wallet/control.js to not require an unlocked wallet when signTx
is false.

Add headers to OPTIONS externalRequest. These are required by CORS when
making POST requests.
@JoeGruffins
Copy link
Member Author

JoeGruffins commented Jun 24, 2022

Seeing a syncing issue after rebase. Looking into it...

Silly me, just needed to use a new dcrd. Looks fine.

There's some js errors I'm not sure I was seeing before, doesn't seem to affect the purchase, but going to put them here. Need to fix these?:

Refused to set unsafe header "origin"  browser-ponyfill.js:504
ControlActions.js:19 Uncaught (in promise) Error: 3 INVALID_ARGUMENT: wallet.NewExternalAddress: invalid operation: cannot use voting accounts for normal transactions
Warning: Each child in a list should have a unique "key" prop.              react_devtools_backend.js:6

Check the render method of `AccountsList`. See https://fb.me/react-warning-keys for more information.
react_devtools_backend.js:6 Warning: Failed prop type: The prop `toggled` is marked as required in `Toggle`, but its value is `undefined`.

@bgptr
Copy link
Collaborator

bgptr commented Jul 7, 2022

@JoeGruffins:

Refused to set unsafe header "origin"  browser-ponyfill.js:504 

This seems to be related to

details.requestHeaders["Origin"] =
"https://dummy-origin-to-fool-trezor-bridge.trezor.io";
}

Without this, the communication to trezor does not work though. I think this warning doesn't need to fix, but probably @matheusd could correct me.

ControlActions.js:19 Uncaught (in promise) Error: 3 INVALID_ARGUMENT: wallet.NewExternalAddress: invalid operation: cannot use voting accounts for normal transactions
Warning: Each child in a list should have a unique "key" prop.              react_devtools_backend.js:6

Check the render method of `AccountsList`. See https://fb.me/react-warning-keys for more information.

I could not reproduce these warnings.

react_devtools_backend.js:6 Warning: Failed prop type: The prop `toggled` is marked as required in `Toggle`, but its value is `undefined`.

I fixed this in #3784. Thanks for the report.

@alexlyp
Copy link
Member

alexlyp commented Nov 22, 2022

Going to be closing this and the other PRs that have sat for quite some time. If you would like to re-open and start to move this PR towards completion, feel free to contact me and I can either reopen this or you may submit another.

@alexlyp alexlyp closed this Nov 22, 2022
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.

None yet

5 participants