Skip to content

Commit 337803f

Browse files
committed
1.0.0-beta.24
1 parent d61b860 commit 337803f

File tree

3 files changed

+198
-2
lines changed

3 files changed

+198
-2
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gaba",
3-
"version": "1.0.0-beta.23",
3+
"version": "1.0.0-beta.24",
44
"description": "Collection of platform-agnostic modules for creating secure data models for cryptocurrency wallets",
55
"license": "MIT",
66
"scripts": {

test.js

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// const {
2+
// AccountTrackerController,
3+
// AddressBookController,
4+
// BlockHistoryController,
5+
// ComposableController,
6+
// CurrencyRateController,
7+
// KeyringController,
8+
// NetworkController,
9+
// NetworkStatusController,
10+
// PhishingController,
11+
// PreferencesController,
12+
// ShapeShiftController,
13+
// TokenRatesController
14+
// } = require('./dist/index.js');
15+
16+
// const BlockTracker = require('eth-block-tracker');
17+
18+
// /**
19+
// * Core controller responsible for composing other GABA controllers together
20+
// * and exposing convenience methods for common wallet operations.
21+
// */
22+
// class Engine {
23+
// /**
24+
// * Creates a CoreController instance
25+
// */
26+
// constructor() {
27+
// this.api = {
28+
// accountTracker: new AccountTrackerController(),
29+
// addressBook: new AddressBookController(),
30+
// blockHistory: new BlockHistoryController(),
31+
// currencyRate: new CurrencyRateController(),
32+
// keyring: new KeyringController(),
33+
// network: new NetworkController(undefined, {
34+
// providerConfig: {}
35+
// }),
36+
// networkStatus: new NetworkStatusController(),
37+
// phishing: new PhishingController(),
38+
// preferences: new PreferencesController(),
39+
// shapeShift: new ShapeShiftController(),
40+
// tokenRates: new TokenRatesController()
41+
// };
42+
43+
// this.datamodel = new ComposableController(this.api);
44+
// this.api.network.subscribe(this.refreshNetwork.bind(this));
45+
// this.refreshNetwork();
46+
// }
47+
48+
// /**
49+
// * Refreshes all controllers that depend on the network
50+
// */
51+
// refreshNetwork() {
52+
// const {
53+
// accountTracker,
54+
// blockHistory,
55+
// network: { provider }
56+
// } = this.api;
57+
// provider.sendAsync = provider.sendAsync.bind(provider);
58+
// provider.start();
59+
// const blockTracker = new BlockTracker({ provider });
60+
// blockHistory.configure({ provider, blockTracker });
61+
// accountTracker.configure({ provider, blockTracker });
62+
// blockTracker.start();
63+
// };
64+
// }
65+
66+
// const engine = new Engine();
67+
68+
// engine.api.blockHistory.subscribe((state) => {
69+
// console.log(state.recentBlocks[state.recentBlocks.length - 1].number);
70+
// });
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
process.env.ETHERSCAN_API_KEY = '1YW9UKTPGGV9K9GR7E916UQ5W26A1P42T5';
82+
const WebCrypto = require('node-webcrypto-ossl');
83+
global.crypto = new WebCrypto();
84+
global.btoa = require('btoa');
85+
global.atob = require('atob');
86+
// global.PBKDF2 = require('pbkdf2');
87+
88+
// // // const encryptor = require('eth-keyring-controller/test/lib/mock-encryptor');
89+
90+
const AccountTrackerController = require('./dist/AccountTrackerController.js').default;
91+
const BlockHistoryController = require('./dist/BlockHistoryController.js').default;
92+
const ComposableController = require('./dist/ComposableController.js').default;
93+
const KeyringController = require('./dist/KeyringController.js').default;
94+
const NetworkController = require('./dist/NetworkController.js').default;
95+
const PreferencesController = require('./dist/PreferencesController.js').default;
96+
const TransactionController = require('./dist/TransactionController.js').default;
97+
98+
const BlockTracker = require('eth-block-tracker');
99+
100+
const network = new NetworkController(undefined, { network: '3', provider: { type: 'ropsten' } });
101+
network.configure({ providerConfig: {} });
102+
network.provider.sendAsync = network.provider.sendAsync.bind(network.provider);
103+
104+
const HttpProvider = require('ethjs-provider-http');
105+
const provider = new HttpProvider('https://ropsten.infura.io');
106+
107+
const blockTracker = new BlockTracker({ provider: network.provider });
108+
blockTracker.start();
109+
110+
// blockTracker.awaitCurrentBlock().then(console.log).catch(console.log);
111+
// blockTracker.on('block', ({ number: blockNumber }) => {
112+
// console.log(parseInt(blockNumber, 16));
113+
// });
114+
// blockTracker.start
115+
// setTimeout(() => {
116+
// blockTracker.on('block', ({ number: blockNumber }) => {
117+
// console.log(parseInt(blockNumber, 16));
118+
// });
119+
// }, 2000);
120+
121+
const accountTracker = new AccountTrackerController({ blockTracker, provider: network.provider });
122+
// const keyring = new KeyringController(undefined, { encryptor });
123+
const keyring = new KeyringController();
124+
const preferences = new PreferencesController();
125+
const blockHistory = new BlockHistoryController({ blockTracker, provider });
126+
127+
const transaction = new TransactionController({
128+
sign: keyring.keyring.signTransaction.bind(keyring.keyring),
129+
provider: network.provider
130+
});
131+
132+
const datamodel = new ComposableController([
133+
accountTracker,
134+
blockHistory,
135+
keyring,
136+
network,
137+
preferences,
138+
transaction
139+
]);
140+
141+
async function add() {
142+
await keyring.createNewVaultAndRestore('foo', 'april shy rubber dose laundry pistol love great aim badge clap labor');
143+
144+
transaction.hub.on('unapprovedTransaction', async (meta) => {
145+
transaction.hub.on(`${transaction.state.transactions[0].id}:confirmed`, (meta) => {
146+
console.log('\n\n\nDONE', meta.transactionHash);
147+
console.log(transaction.state.transactions[0]);
148+
// console.log(transaction.state);
149+
});
150+
151+
// promise.then(hash => console.log('\n\n\n\n\n\n\n', hash, '\n\n\n\n\n')).catch(console.log);
152+
153+
await transaction.approveTransaction(transaction.state.transactions[0].id);
154+
// console.log(transaction.state);
155+
// transaction.cancelTransaction(transaction.state.transactions[0].id);
156+
// transaction.wipeTransactions();
157+
// console.log(transaction.state);
158+
});
159+
160+
transaction.addTransaction({
161+
from: "0xC38bF1aD06ef69F0c04E29DBeB4152B4175f0A8D",
162+
to: "0xE6509775F3f3614576C0d83f8647752f87CD6659",
163+
value: "0x989680",
164+
gas: "0x0"
165+
});
166+
}
167+
168+
add();
169+
170+
// const HttpProvider = require('ethjs-provider-http');
171+
// var Web3 = require('web3');
172+
// var web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io"));
173+
// var Tx = require('ethereumjs-tx');
174+
// var privateKey = new Buffer('4e102d5bb594e0dae997158a1bb2fd2839e5f3d4a95682537c640d96735573ee', 'hex');
175+
176+
// var rawTx = {
177+
// chainId: '3',
178+
// from: '0x3244e191f1b4903970224322180f1fbbc415696b',
179+
// gas: '0x5208',
180+
// gasPrice: '0xc845880',
181+
// nonce: '0x2',
182+
// to: '0xc38bf1ad06ef69f0c04e29dbeb4152b4175f0a8d',
183+
// value: '0x0',
184+
// };
185+
186+
// var tx = new Tx(rawTx);
187+
// tx.sign(privateKey);
188+
189+
// var serializedTx = tx.serialize();
190+
191+
// console.log(serializedTx.toString('hex'));
192+
// // f889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f
193+
194+
// web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
195+
// console.log(err, hash);
196+
// });

0 commit comments

Comments
 (0)