Skip to content

Commit 9a6a903

Browse files
jernejpregeljjernejpregelj
jernejpregelj
authored and
jernejpregelj
committed
bigchaindb2.x, npm updates
1 parent 356cf59 commit 9a6a903

11 files changed

+232
-345
lines changed

.babelrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"presets": ["es2015"]
2+
"presets": [
3+
"env"
4+
]
35
}

package.json

+16-11
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,28 @@
99
},
1010
"license": "Apache-2.0",
1111
"dependencies": {
12-
"bigchaindb-driver": "^0.3.0",
13-
"bip39": "^2.3.1",
14-
"graphql": "^0.13.1",
15-
"graphql-type-json": "^0.1.4"
12+
"bigchaindb-driver": "^4.1.0",
13+
"bip39": "^2.5.0",
14+
"graphql": "^0.13.2",
15+
"graphql-type-json": "^0.2.1"
1616
},
1717
"devDependencies": {
18-
"babel-cli": "^6.24.1",
19-
"babel-eslint": "^8.0.3",
20-
"babel-loader": "^7.1.1",
18+
"babel-cli": "^6.26.0",
19+
"babel-eslint": "^8.2.6",
20+
"babel-loader": "^7.1.5",
21+
"babel-preset-env": "^1.7.0",
2122
"babel-preset-es2015": "^6.24.1",
22-
"cross-env": "^5.0.3",
23+
"cross-env": "^5.2.0",
2324
"eslint": "^4.13.1",
2425
"eslint-config-ascribe": "^3.0.5",
2526
"eslint-plugin-import": "^2.8.0",
26-
"release-it": "^7.0.2",
27-
"rimraf": "^2.5.4",
28-
"webpack": "^3.4.1"
27+
"release-it": "^7.5.0",
28+
"rimraf": "^2.6.2",
29+
"webpack": "^4.16.1",
30+
"webpack-cli": "^3.0.8",
31+
"webpack-concat-plugin": "^3.0.0",
32+
"webpack-merge": "^4.1.3",
33+
"webpack-sources": "^1.1.0"
2934
},
3035
"scripts": {
3136
"lint": "./node_modules/eslint/bin/eslint.js ./src",

plugins/add-vendors-plugin.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const { ConcatSource } = require('webpack-sources')
2+
3+
module.exports = class AddVendorsPlugin {
4+
constructor(base) {
5+
this.base = base
6+
}
7+
8+
apply(compiler) {
9+
compiler.hooks.emit.tapAsync(
10+
`AddVendorsPlugin ${this.base}`,
11+
(compilation, callback) => {
12+
const main = compilation.assets[`main.${this.base}`]
13+
const mainMap = compilation.assets[`main.${this.base}.map`]
14+
const vendor = compilation.assets[`vendors.${this.base}`]
15+
16+
if (main && vendor) {
17+
const compiledAsset = new ConcatSource(main.children[0])
18+
compiledAsset.add(vendor)
19+
compiledAsset.add(main.children[1])
20+
compilation.assets = {}
21+
compilation.assets[this.base] = compiledAsset
22+
} else if (main && mainMap) {
23+
compilation.assets = {}
24+
compilation.assets[this.base] = main
25+
compilation.assets[`${this.base}.map`] = mainMap
26+
}
27+
callback()
28+
}
29+
)
30+
}
31+
}

src/conn.js

+29-32
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,38 @@ export default class BigchainDBGraphQLConnection {
3838
.then(assetList => Promise.all(assetList.map(asset => this.conn.getTransaction(asset.id))))
3939
}
4040

41-
createTransaction(publicKey, privateKey, asset, metadata) {
42-
// Create a transation
43-
const tx = driver.Transaction.makeCreateTransaction(
44-
asset,
45-
metadata,
46-
[
47-
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(publicKey))
48-
],
49-
publicKey
50-
)
41+
createTransaction(publicKey, privateKey, payload, metadata) {
42+
try {
43+
// Create a transation
44+
const tx = driver.Transaction.makeCreateTransaction(
45+
payload,
46+
metadata,
47+
[
48+
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(publicKey))
49+
],
50+
publicKey
51+
)
5152

52-
// sign/fulfill the transaction
53-
const txSigned = driver.Transaction.signTransaction(tx, privateKey)
54-
55-
// send it off to BigchainDB
56-
return this.conn.postTransaction(txSigned)
57-
.then(() => this.conn.pollStatusAndFetchTransaction(txSigned.id))
58-
.then(() => txSigned)
53+
// sign/fulfill the transaction
54+
const txSigned = driver.Transaction.signTransaction(tx, privateKey)
55+
return this.conn.postTransactionCommit(txSigned).then(() => txSigned)
56+
} catch (error) {
57+
return Promise.reject(error)
58+
}
5959
}
6060

6161
transferTransaction(tx, fromPublicKey, fromPrivateKey, toPublicKey, metadata) {
62-
const txTransfer = driver.Transaction.makeTransferTransaction(
63-
tx,
64-
metadata,
65-
[
66-
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(toPublicKey))
67-
],
68-
0
69-
)
70-
71-
const txTransferSigned = driver.Transaction.signTransaction(txTransfer, fromPrivateKey)
72-
// send it off to BigchainDB
73-
return this.conn.postTransaction(txTransferSigned)
74-
.then(() =>
75-
this.conn.pollStatusAndFetchTransaction(txTransferSigned.id))
76-
.then(() => txTransferSigned)
62+
try {
63+
const txTransfer = driver.Transaction.makeTransferTransaction(
64+
[{ 'tx': tx, 'output_index': 0 }],
65+
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(toPublicKey))],
66+
metadata,
67+
)
68+
const txTransferSigned = driver.Transaction.signTransaction(txTransfer, fromPrivateKey)
69+
// send it off to BigchainDB
70+
return this.conn.postTransactionCommit(txTransferSigned).then(() => txTransferSigned)
71+
} catch (error) {
72+
return Promise.reject(error)
73+
}
7774
}
7875
}

src/schema.js

+1-80
Original file line numberDiff line numberDiff line change
@@ -50,61 +50,10 @@ export default class BigchainDBGraphQLSchema {
5050
asset: { type: GraphQLJSON },
5151
metadata: { type: GraphQLJSON },
5252
inputs: { type: new GraphQLList(this.InputType) },
53-
outputs: { type: new GraphQLList(this.OutputType) },
54-
blocks: {
55-
type: new GraphQLList(this.BlockType),
56-
resolve(root) {
57-
return conn.listBlocks(root.id)
58-
}
59-
}
53+
outputs: { type: new GraphQLList(this.OutputType) }
6054
})
6155
})
6256

63-
this.VoteType = new GraphQLObjectType({
64-
name: 'Vote',
65-
fields: {
66-
node_pubkey: { type: GraphQLString },
67-
signature: { type: GraphQLString },
68-
vote: {
69-
type: new GraphQLObjectType({
70-
name: 'VoteIntern',
71-
fields: {
72-
voting_for_block: { type: GraphQLString },
73-
previous_block: { type: GraphQLString },
74-
is_block_valid: { type: GraphQLBoolean },
75-
invalid_reason: { type: GraphQLString },
76-
timestamp: { type: GraphQLString }
77-
}
78-
})
79-
}
80-
}
81-
})
82-
83-
this.BlockType = new GraphQLObjectType({
84-
name: 'Block',
85-
fields: {
86-
id: { type: GraphQLString },
87-
block: {
88-
type: new GraphQLObjectType({
89-
name: 'BlockIntern',
90-
fields: {
91-
timestamp: { type: GraphQLString },
92-
transactions: { type: new GraphQLList(this.TransactionType) },
93-
node_pubkey: { type: GraphQLString },
94-
voters: { type: new GraphQLList(GraphQLString) },
95-
}
96-
})
97-
},
98-
votes: {
99-
type: new GraphQLList(this.VoteType),
100-
resolve(root) {
101-
return conn.listVotes(root.id)
102-
}
103-
},
104-
signature: { type: GraphQLString }
105-
}
106-
})
107-
10857
this.queryType = new GraphQLObjectType({
10958
name: 'Query',
11059
fields: {
@@ -137,34 +86,6 @@ export default class BigchainDBGraphQLSchema {
13786
return conn.listOutputs(public_key, spent)
13887
}
13988
},
140-
block: {
141-
type: this.BlockType,
142-
args: {
143-
id: { type: GraphQLString }
144-
},
145-
resolve(root, { id }) {
146-
return conn.getBlock(id)
147-
}
148-
},
149-
blocks: {
150-
type: new GraphQLList(this.BlockType),
151-
args: {
152-
transaction_id: { type: GraphQLString },
153-
status: { type: GraphQLString },
154-
},
155-
resolve(root, { transaction_id, status }) { // eslint-disable-line camelcase
156-
return conn.listBlocks(transaction_id, status)
157-
}
158-
},
159-
votes: {
160-
type: new GraphQLList(this.VoteType),
161-
args: {
162-
block_id: { type: GraphQLString },
163-
},
164-
resolve(root, { block_id }) { // eslint-disable-line camelcase
165-
return conn.listVotes(block_id)
166-
}
167-
},
16889
search: {
16990
type: new GraphQLList(this.TransactionType),
17091
args: {

0 commit comments

Comments
 (0)