Skip to content

Commit

Permalink
Merge branch 'aptos' of github.com:pontem-network/aptos-mask into aptos
Browse files Browse the repository at this point in the history
  • Loading branch information
sirWill committed May 24, 2022
2 parents 752c43a + 7d52d0b commit 01ff39d
Show file tree
Hide file tree
Showing 125 changed files with 28,524 additions and 37 deletions.
9 changes: 8 additions & 1 deletion SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
### Install & Link dependencies of packages
- Go to `./packages` and in each folder run `yarn` command.
- Run `./development/packages-link.sh` script. This will create all npm links between packages and main package.
- Packages `pontem-block-tracker`, `pontem-controllers`, `pontem-nonce-tracker`, `pontem-util` and `pontem-wallet` need to be built in order for the changes to be applied in the main project.
- Packages in list need to be built in order for the changes to be applied in the main project.:
- `pontem-block-tracker`
- `pontem-controllers`
- `pontem-nonce-tracker`
- `pontem-util`
- `pontem-providers`
- `pontem-json-rpc-middleware`
- `pontem-wallet`

Before the first run, be sure to build these packages.
Pay attention to the version of nodejs in each project for build.
Expand Down
14 changes: 7 additions & 7 deletions app/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ const inpageContent = fs.readFileSync(
const inpageSuffix = `//# sourceURL=${extension.runtime.getURL('inpage.js')}\n`;
const inpageBundle = inpageContent + inpageSuffix;

const CONTENT_SCRIPT = 'metamask-contentscript';
const INPAGE = 'metamask-inpage';
const PROVIDER = 'metamask-provider';
const CONTENT_SCRIPT = 'aptosmask-contentscript';
const INPAGE = 'aptosmask-inpage';
const PROVIDER = 'aptosmask-provider';

// TODO:LegacyProvider: Delete
const LEGACY_CONTENT_SCRIPT = 'contentscript';
const LEGACY_INPAGE = 'inpage';
const LEGACY_PROVIDER = 'provider';
const LEGACY_PUBLIC_CONFIG = 'publicConfig';
const LEGACY_CONTENT_SCRIPT = 'legacy-contentscript';
const LEGACY_INPAGE = 'legacy-inpage';
const LEGACY_PROVIDER = 'legacy-provider';
const LEGACY_PUBLIC_CONFIG = 'legacy-publicConfig';

if (shouldInjectProvider()) {
injectScript(inpageBundle);
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/network/createAptosRestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
createInflightCacheMiddleware,
createBlockTrackerInspectorMiddleware,
providerFromMiddleware,
} from 'eth-json-rpc-middleware';
} from '@pontem/pontem-json-rpc-middleware';

import { createFetchMiddleware } from '@pontem/pontem-aptos-middleware';
import { PollingBlockTracker } from '@pontem/pontem-block-tracker';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createScaffoldMiddleware, mergeMiddleware } from 'json-rpc-engine';
import { createWalletMiddleware } from 'eth-json-rpc-middleware';
import { createWalletMiddleware } from '@pontem/pontem-json-rpc-middleware';
import {
createPendingNonceMiddleware,
createPendingTxMiddleware,
Expand Down
30 changes: 18 additions & 12 deletions app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,29 +1067,35 @@ export default class TransactionController extends EventEmitter {
chainId,
gasLimit: txMeta.txParams.gas,
};

function fromHexToNumber(hex) {
return new BigNumber(hex, 16).toString(10)
}
// sign tx
const fromAddress = txParams.from;
console.log('[Pontem][TransactionController] txParams', { txParams, amount: new BigNumber(txParams.value, 16).toString(10) });

// TODO move into create tx step
const payload = {
sender: fromAddress,
sequence_number: parseInt(txParams.nonce, 16).toString(),
max_gas_amount: "1000",
gas_unit_price: "1",
sequence_number: fromHexToNumber(txParams.nonce),
max_gas_amount: fromHexToNumber(txMeta.txParams.gas),
gas_unit_price: fromHexToNumber(txMeta.txParams.gasPrice),
gas_currency_code: "XUS",
expiration_timestamp_secs: (Math.floor(Date.now() / 1000) + 600).toString(),
payload: {
type: "script_function_payload",
function: "0x1::TestCoin::transfer",
type_arguments: [],
arguments: [
txParams.to,
new BigNumber(txParams.value, 16).div(new BigNumber(10, 10).pow(18)).toString(10)
]
},
payload: txParams.payload,
}

// {
// type: "script_function_payload",
// function: "0x1::Coin::transfer",
// type_arguments: ['0x1::TestCoin::TestCoin'],
// arguments: [
// txParams.to,
// new BigNumber(txParams.value, 16).div(new BigNumber(10, 10).pow(18)).toString(10)
// ]
// }

const msgForSign = await (new Promise((resolve, reject) => {
this.pontemQuery.createSignMessage(payload, (err, response) => {
if(err) {
Expand Down
10 changes: 9 additions & 1 deletion app/scripts/controllers/transactions/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const normalizers = {
nonce: addHexPrefix,
value: addHexPrefix,
data: addHexPrefix,
payload: (payload) => ({
arguments: payload.arguments,
function: payload.function,
type: payload.type,
type_arguments: payload.type_arguments || payload.typeArguments
}),
gas: addHexPrefix,
gasPrice: addHexPrefix,
maxFeePerGas: addHexPrefix,
Expand Down Expand Up @@ -137,7 +143,7 @@ export function validateTxParams(txParams, eip1559Compatibility = true) {
'Invalid transaction params: must be an object.',
);
}
if (!txParams.to && !txParams.data) {
if (!txParams.to && !txParams.data && !txParams.payload) {
throw ethErrors.rpc.invalidParams(
'Invalid transaction params: must specify "data" for contract deployments, or "to" (and optionally "data") for all other types of transactions.',
);
Expand Down Expand Up @@ -220,6 +226,8 @@ export function validateTxParams(txParams, eip1559Compatibility = true) {
);
}
break;
case 'payload':
break;
default:
ensureFieldIsString(txParams, key);
}
Expand Down
7 changes: 4 additions & 3 deletions app/scripts/inpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cleanContextForImports();
/* eslint-disable import/first */
import log from 'loglevel';
import { WindowPostMessageStream } from '@metamask/post-message-stream';
import { initializeProvider } from '@metamask/providers/dist/initializeInpageProvider';
import { initializeProvider } from '@pontem/pontem-providers/dist/initializeInpageProvider';

restoreContextAfterImports();

Expand All @@ -45,12 +45,13 @@ log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn');

// setup background connection
const metamaskStream = new WindowPostMessageStream({
name: 'metamask-inpage',
target: 'metamask-contentscript',
name: 'aptosmask-inpage',
target: 'aptosmask-contentscript',
});

initializeProvider({
connectionStream: metamaskStream,
logger: log,
jsonRpcStreamName: 'aptosmask-provider',
shouldShimWeb3: true,
});
2 changes: 1 addition & 1 deletion app/scripts/lib/account-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export default class AccountTracker {

let balance = '0x0';
(resources || []).forEach(resource => {
if(resource.type === '0x1::TestCoin::Balance') {
if(resource.type === '0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>') {
balance = bnToHex(new BigNumber(resource.data.coin.value, 10).times(new BigNumber(10, 10).pow(18)))
}
})
Expand Down
5 changes: 3 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { errorCodes as rpcErrorCodes, ethErrors } from 'eth-rpc-errors';
import { Mutex } from 'await-semaphore';
import { stripHexPrefix } from 'ethereumjs-util';
import log from 'loglevel';

import TrezorKeyring from 'eth-trezor-keyring';
import LedgerBridgeKeyring from '@metamask/eth-ledger-bridge-keyring';
import LatticeKeyring from 'eth-lattice-keyring';
Expand Down Expand Up @@ -3029,15 +3030,15 @@ export default class MetamaskController extends EventEmitter {

// messages between inpage and background
this.setupProviderConnection(
mux.createStream('metamask-provider'),
mux.createStream('aptosmask-provider'),
sender,
_subjectType,
);

// TODO:LegacyProvider: Delete
if (sender.url) {
// legacy streams
this.setupPublicConfig(mux.createStream('publicConfig'));
this.setupPublicConfig(mux.createStream('legacy-publicConfig'));
}
}

Expand Down
6 changes: 6 additions & 0 deletions development/packages-link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ cd $PACKAGES_DIR/pontem-util && bash ./link.sh
cd $PACKAGES_DIR/pontem-wallet && bash ./link.sh
cd $PACKAGES_DIR/pontem-hd-keyring && bash ./link.sh
cd $PACKAGES_DIR/pontem-keyring-controller && bash ./link.sh
cd $PACKAGES_DIR/pontem-json-rpc-middleware && bash ./link.sh
cd $PACKAGES_DIR/pontem-json-rpc-filters && bash ./link.sh
cd $PACKAGES_DIR/pontem-providers && bash ./link.sh

cd $SRC_DIR/..

Expand All @@ -26,3 +29,6 @@ yarn link @pontem/pontem-util
yarn link @pontem/pontem-wallet
yarn link @pontem/pontem-hd-keyring
yarn link @pontem/pontem-keyring-controller
yarn link @pontem/pontem-json-rpc-middleware
yarn link @pontem/pontem-json-rpc-filters
yarn link @pontem/pontem-providers
8 changes: 2 additions & 6 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,6 @@
}
},
"@starcoin/stc-wallet": {
"globals": {
"console.log": true
},
"packages": {
"@starcoin/starcoin": true,
"@starcoin/stc-util": true
Expand Down Expand Up @@ -2008,8 +2005,6 @@
"results": "write"
},
"packages": {
"@metamask/safe-event-emitter": true,
"async-mutex": true,
"await-semaphore": true,
"eth-json-rpc-middleware": true,
"eth-query": true,
Expand Down Expand Up @@ -3701,6 +3696,7 @@
},
"md5.js": {
"packages": {
"buffer": true,
"hash-base": true,
"inherits": true,
"safe-buffer": true
Expand Down Expand Up @@ -5384,4 +5380,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3715,6 +3715,7 @@
},
"md5.js": {
"packages": {
"buffer": true,
"hash-base": true,
"inherits": true,
"safe-buffer": true
Expand Down Expand Up @@ -5398,4 +5399,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3696,6 +3696,7 @@
},
"md5.js": {
"packages": {
"buffer": true,
"hash-base": true,
"inherits": true,
"safe-buffer": true
Expand Down Expand Up @@ -5379,4 +5380,4 @@
}
}
}
}
}
3 changes: 3 additions & 0 deletions packages/pontem-json-rpc-filters/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto

yarn.lock linguist-generated=false
4 changes: 4 additions & 0 deletions packages/pontem-json-rpc-filters/.github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Lines starting with '#' are comments.
# Each line is a file pattern followed by one or more owners.

* @MetaMask/devs
15 changes: 15 additions & 0 deletions packages/pontem-json-rpc-filters/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'daily'
time: '06:00'
allow:
- dependency-name: '@metamask/*'
target-branch: 'main'
versioning-strategy: 'increase-if-necessary'
open-pull-requests-limit: 10
56 changes: 56 additions & 0 deletions packages/pontem-json-rpc-filters/.github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build, Lint, and Test

on:
push:
branches: [main]
pull_request:

jobs:
build-lint-test:
name: Build, Lint, and Test
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Get Yarn cache directory
run: echo "::set-output name=YARN_CACHE_DIR::$(yarn cache dir)"
id: yarn-cache-dir
- name: Get Yarn version
run: echo "::set-output name=YARN_VERSION::$(yarn --version)"
id: yarn-version
- name: Cache yarn dependencies
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir.outputs.YARN_CACHE_DIR }}
key: yarn-cache-${{ runner.os }}-${{ steps.yarn-version.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}
- run: yarn --frozen-lockfile
- run: yarn allow-scripts
- run: yarn build
- run: yarn lint
- run: yarn test
- name: Validate RC changelog
if: ${{ startsWith(github.head_ref, 'release/') }}
run: yarn auto-changelog validate --rc
- name: Validate changelog
if: ${{ !startsWith(github.head_ref, 'release/') }}
run: yarn auto-changelog validate
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty after building"
exit 1
fi
all-jobs-pass:
name: All jobs pass
runs-on: ubuntu-20.04
needs:
- build-lint-test
steps:
- run: echo "Great success!"
Loading

0 comments on commit 01ff39d

Please sign in to comment.