Skip to content

ERC20#2395

Merged
matiu merged 18 commits into
bitpay:masterfrom
justinkook:erc20
Nov 10, 2019
Merged

ERC20#2395
matiu merged 18 commits into
bitpay:masterfrom
justinkook:erc20

Conversation

@justinkook
Copy link
Copy Markdown
Contributor

@justinkook justinkook commented Sep 17, 2019

ERC20 changes for BWC/BWS and crypto-wallet-core

Related Copay ERC20 merge request:
https://github.com/bitpay/copay/pull/10162

To install BWC into copay requires:
#2518

Also relies on MR to fix broadcast error: #2520

[warn] ERROR: 500 - "Returned error: Invalid params: invalid type: sequence, expected a 0x-prefixed, hex-encoded vector of bytes."

ERC20 payProV2 proposal:

Changes:

Copay:

  1. Fetch ERC20 PayProV2 selectPaymentOptions returns instructions as an array..
  2. Create 1 txp with multiple outputs for each instruction:
txp.outputs: [{
    toAddress: '0x..RecievingAddress…',
    amount: 0,
    gasLimit: 21000
}, {
    toAddress: '0x..TokenContractAddress...',
    amount: 0,
    gasLimit: 93028
}]

BWC/BWS:

  1. Loop through outputs and create rawTx for each output.
for (const output of txp.outputs) {
    const rawTx = CWC.Transactions.create(…)
}
  1. RawTx gets returned as an array of tx hashes

return ['0x12345', '0x98765']

  1. Loop through tx array and return array of signatures.
for (const rawTx of txs) {
       const signedTx = CWC.Transaction.applySignatures(...)
}

return ['signature1', 'signature2']
4. Published txp has multiple outputs and property raw as an array of rawTxs instead of a string.
5. POST payProV2 sendSignedTxs with array of signedTxs.

@matiu
Copy link
Copy Markdown
Contributor

matiu commented Sep 18, 2019

ill review this once ETH BWS is on prod.

Comment thread packages/crypto-wallet-core/src/transactions/index.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/blockchainexplorers/v8.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/blockchainexplorer.ts Outdated
Comment thread packages/bitcore-wallet-client/src/lib/api.ts
Comment thread packages/bitcore-wallet-client/src/lib/api.ts Outdated
Comment thread packages/bitcore-wallet-client/src/lib/api.ts Outdated
Comment thread packages/bitcore-wallet-client/src/lib/api.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/server.ts
@justinkook justinkook force-pushed the erc20 branch 9 times, most recently from bf70579 to a737bce Compare October 24, 2019 15:14
Copy link
Copy Markdown
Contributor

@micahriggan micahriggan left a comment

Choose a reason for hiding this comment

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

This is looking pretty good

Comment thread packages/bitcore-wallet-client/src/lib/key.ts Outdated
Comment thread packages/bitcore-wallet-service/test/integration/helpers.js Outdated
@justinkook justinkook force-pushed the erc20 branch 3 times, most recently from 71255c5 to e3a0df3 Compare November 4, 2019 22:37
Comment thread packages/bitcore-wallet-service/src/lib/chain/btc/index.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/chain/btc/index.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/chain/btc/index.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/chain/eth/index.ts Outdated
Comment thread packages/bitcore-wallet-client/src/lib/common/utils.ts
Copy link
Copy Markdown
Contributor

@matiu matiu left a comment

Choose a reason for hiding this comment

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

Great work!

Comment thread packages/bitcore-wallet-client/src/lib/common/utils.ts Outdated
Comment thread packages/bitcore-wallet-client/src/lib/api.ts
// bitcore users id for txid...
t.id = CWC.Transactions.getHash({ tx: raw, chain: txp.coin.toUpperCase() });
// bitcore users id for txid...
t.id = CWC.Transactions.getHash({ tx: signed, chain });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this should be out of the loop. we should store ids = [ txs.map(x=> hash(x))], and id = ids[0],
so all ids get stored on BWS, and also we keep some compatibility with id.

Comment thread packages/bitcore-wallet-client/src/lib/api.ts Outdated
Comment thread packages/bitcore-wallet-client/src/lib/api.ts
Comment thread packages/bitcore-wallet-service/src/lib/server.ts Outdated
Comment thread packages/bitcore-wallet-service/test/integration/helpers.js Outdated
Comment thread packages/bitcore-wallet-service/test/integration/server.js
Comment thread packages/bitcore-wallet-service/test/integration/server.js
Comment thread packages/bitcore-wallet-service/test/integration/server.js
Comment thread packages/bitcore-wallet-service/src/lib/model/txproposal.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/server.ts
@matiu
Copy link
Copy Markdown
Contributor

matiu commented Nov 10, 2019

Great job @justinkook and @micahriggan !

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.

4 participants