Skip to content

Commit 7f146fa

Browse files
authored
Merge branch 'chainsql-test' into feature/schema
2 parents 2427af4 + d55643b commit 7f146fa

23 files changed

Lines changed: 1936 additions & 116 deletions

lib/crypto.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
// requires
3-
const keypairs = require('chainsql-keypairs');
3+
const keypairs = require('chainsql-keypairs-test');
44

55
const hashjs = require('hash.js');
66
const elliptic = require('elliptic');

lib/error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const chainsqldError = require('chainsql-lib').ChainsqlLibCommon.errors.ChainsqldError;
3+
const chainsqldError = require('chainsql-lib-test').ChainsqlLibCommon.errors.ChainsqldError;
44

55
function chainsqlError( errMsg ) {
66
let errName = "apiGeneralErr";

lib/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
const path = require('path');
3-
const common = require('chainsql-lib').ChainsqlLibCommon;
4-
const keypairs = require('chainsql-keypairs');
3+
const common = require('chainsql-lib-test').ChainsqlLibCommon;
4+
const keypairs = require('chainsql-keypairs-test');
55
const cryptoo = require('crypto');
66
const crypto = require('./crypto');
77
const opType = require('./config').opType;

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"name": "chainsql",
3-
"version": "0.6.69",
2+
"name": "chainsql-test",
3+
"version": "0.6.71",
44
"description": "An database driver for chainsql ",
55
"main": "src/index.js",
66
"scripts": {
77
"test": "mocha"
88
},
99
"dependencies": {
1010
"bignumber.js": "^2.4.0",
11-
"chainsql-keypairs": "^0.10.11",
12-
"chainsql-lib": "^0.17.44",
11+
"chainsql-keypairs-test": "^0.10.16",
12+
"chainsql-lib-test": "^0.17.52",
1313
"co": "^4.6.0",
1414
"elliptic": "^5.1.0",
1515
"hash.js": "^1.0.3",
@@ -22,7 +22,8 @@
2222
"ws": "^7.2.0"
2323
},
2424
"devDependencies": {
25-
"mocha": "~2.3.3"
25+
"mocha": "~2.3.3",
26+
"chai": "^4.2.0"
2627
},
2728
"repository": {
2829
"type": "git",

solidity-example/solidity-TableTxs.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ contract DBTest {
8787

8888
function sqlTransaction(address owner,string tableName) public{
8989
db.beginTrans();
90-
owner.insert(tableName, "[{\"account\":\"zU42yDW3fzFjGWosdeVjVasyPsF4YHj224\", \"id\":1}, {\"account\":\"zU42yDW3fzFjGWosdeVjVasyPsF4YHj224\", \"id\":2}]");
91-
owner.deletex(tableName, "{\"id\":1}");
92-
owner.update(tableName, "{\"account\":\"id==2\"}", "{\"id\": 2}");
90+
msg.sender.insert(owner,tableName, "[{\"account\":\"zU42yDW3fzFjGWosdeVjVasyPsF4YHj224\", \"id\":1}, {\"account\":\"zU42yDW3fzFjGWosdeVjVasyPsF4YHj224\", \"id\":2}]");
91+
msg.sender.deletex(owner,tableName, "{\"id\":1}");
92+
msg.sender.update(owner,tableName, "{\"account\":\"id==2\"}", "{\"id\": 2}");
9393
db.commit();
9494
}
9595

src/index.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict'
22
const crypto = require('../lib/crypto');
3-
const keypairs = require('chainsql-keypairs');
3+
const keypairs = require('chainsql-keypairs-test');
44
const EventManager = require('./eventManager')
55
const _ = require('lodash');
66

7-
const RippleAPI = require('chainsql-lib').ChainsqlLibAPI;
7+
const RippleAPI = require('chainsql-lib-test').ChainsqlLibAPI;
88
const Submit = require('./submit');
99
const Ripple = require('./ripple');
1010
const chainsqlError = require('../lib/error');
@@ -20,6 +20,7 @@ const Table = require('./table');
2020
const Contract = require('./smartContract');
2121
const util = require('../lib/util');
2222
const { utils } = require('elliptic');
23+
const co = require('co');
2324
const opType = require('../lib/config').opType;
2425
const convertStringToHex = util.convertStringToHex;
2526
const getCryptAlgTypeFromAccout = util.getCryptAlgTypeFromAccout;
@@ -320,6 +321,10 @@ ChainsqlAPI.prototype.createTable = function (name, raw, inputOpt) {
320321
var token = generateToken(that.connect.secret);
321322
var symKey = decodeToken(that, token);
322323
var regSoftGMSeed = /^[a-zA-Z1-9]{51,51}/
324+
325+
326+
// 原始的大小
327+
console.log("pre :",payment.raw);
323328

324329
if(that.connect.secret === "gmAlg") {
325330
payment.raw = crypto.symEncrypt(symKey, payment.raw, "gmAlg").toUpperCase();
@@ -329,7 +334,13 @@ ChainsqlAPI.prototype.createTable = function (name, raw, inputOpt) {
329334
else {
330335
payment.raw = crypto.symEncrypt(symKey, payment.raw).toUpperCase();
331336
}
337+
338+
//
339+
console.log("after :",payment.raw);
340+
332341
payment.token = token.toUpperCase();
342+
343+
console.log("token :",payment.token);
333344
} else {
334345
payment.raw = convertStringToHex(payment.raw);
335346
}
@@ -685,7 +696,17 @@ function handleCommit(ChainSQL, object, resolve, reject) {
685696
var secret = decodeToken(ChainSQL, token);
686697
if (cache[i].Raw) {
687698
if (cache[i].OpType != opType.t_grant) {
688-
const algType = ChainSQL.connect.secret === "gmAlg" ? "gmAlg" : "aes";
699+
//const algType = ChainSQL.connect.secret === "gmAlg" ? "gmAlg" : "aes";
700+
701+
702+
var regSoftGMSeed = /^[a-zA-Z1-9]{51,51}/
703+
704+
let algType = "aes";
705+
if(ChainSQL.connect.secret === "gmAlg"){
706+
algType = "gmAlg";
707+
}else if(regSoftGMSeed.test(ChainSQL.connect.secret)){
708+
algType = "softGMAlg";
709+
}
689710
cache[i].Raw = crypto.symEncrypt(secret, JSON.stringify(cache[i].Raw), algType).toUpperCase();
690711
} else {
691712
cache[i].Raw = convertStringToHex(JSON.stringify(cache[i].Raw));

src/ripple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var util = require('../lib/util');
33
var Submit = require('./submit');
44
const FloatOperation = require('../lib/floatOperation');
5-
var chainsqlLibUtils = require('chainsql-lib').ChainsqlLibUtil;
5+
var chainsqlLibUtils = require('chainsql-lib-test').ChainsqlLibUtil;
66

77
class Ripple extends Submit {
88
constructor(ChainsqlAPI) {

src/smartContract.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
var util = require('../lib/util');
44

55
const _ = require('lodash');
6-
var chainsqlLibUtils = require('chainsql-lib').ChainsqlLibUtil;
7-
const keypairs = require('chainsql-keypairs');
6+
var chainsqlLibUtils = require('chainsql-lib-test').ChainsqlLibUtil;
7+
const keypairs = require('chainsql-keypairs-test');
88
const chainsqlUtils = require('../lib/util');
99
const chainsqlError = require('../lib/error');
1010
var abi = require('web3-eth-abi');

src/submit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22
var util = require('../lib/util');
3-
const RippleAPI = require('chainsql-lib').ChainsqlLibAPI;
3+
const RippleAPI = require('chainsql-lib-test').ChainsqlLibAPI;
44
const Connection = require('./connect');
55

66
class Submit {

src/table.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Table extends Submit {
1919
this.exec = '';
2020
this.field = null;
2121
this.connect = ChainsqlAPI.connect;
22-
this.cache = [];
22+
this.cache = [];
23+
this.txsHashFillField = null;
2324
}
2425

2526
submit (cb) {
@@ -59,13 +60,18 @@ class Table extends Submit {
5960
}
6061
}
6162

62-
Table.prototype.insert = function(raw, field) {
63+
Table.prototype.insert = function(raw, autoField ,txsHashFillField) {
6364
if (!this.tab) throw chainsqlError('you must appoint the table name');
6465
if (this.exec !== '' && this.exec !== 'r_insert') throw chainsqlError('Object can not hava function insert');
6566
var that = this;
66-
if (field) {
67-
this.field = field;
67+
if (autoField) {
68+
this.field = autoField;
69+
}
70+
71+
if (txsHashFillField) {
72+
this.txsHashFillField = txsHashFillField;
6873
}
74+
6975
if (Object.prototype.toString.call(raw) === '[object Array]') {
7076
raw.forEach(function(item) {
7177
that.query.push(item);
@@ -90,7 +96,7 @@ Table.prototype.insert = function(raw, field) {
9096
}
9197
}
9298

93-
Table.prototype.update = function(raw,field) {
99+
Table.prototype.update = function(raw,field,txsHashFillField) {
94100
if (!this.tab) throw chainsqlError('you must appoint the table name');
95101
if (this.exec !== 'r_get') throw chainsqlError('Object can not hava function update');
96102
this.query.unshift(raw);
@@ -99,6 +105,10 @@ Table.prototype.update = function(raw,field) {
99105
this.field = field;
100106
}
101107

108+
if (txsHashFillField) {
109+
this.txsHashFillField = txsHashFillField;
110+
}
111+
102112
this.exec = 'r_update';
103113
if (this.transaction) {
104114
this.cache.push({
@@ -397,10 +407,18 @@ Table.prototype.prepareJson = function() {
397407
}],
398408
tsType: 'SQLStatement'
399409
};
400-
if ( (that.exec == 'r_insert' || that.exec == 'r_update') && that.field) {
401-
payment.autoFillField = convertStringToHex(that.field);
402-
}
410+
if ( (that.exec == 'r_insert' || that.exec == 'r_update') ) {
411+
412+
if(that.field){
413+
payment.autoFillField = convertStringToHex(that.field);
414+
}
403415

416+
if ( that.txsHashFillField) {
417+
payment.txsHashFillField = convertStringToHex(that.txsHashFillField);
418+
}
419+
420+
}
421+
404422
return new Promise(function (resolve, reject) {
405423
prepareTable(that, payment, resolve, reject);
406424
});

0 commit comments

Comments
 (0)