Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var assert = require("assert");
var ByteBuffer = require("protobufjs").ByteBuffer;
var Long = require("protobufjs").Long;
var openchain = require("../index");
describe("encoding", function () {
it("encodeString", function () {
var result = openchain.encoding.encodeString("ABC");
assert.equal(result.toHex(), "414243");
});
it("encodeInt64", function () {
var result = openchain.encoding.encodeInt64(Long.fromString("25000"));
assert.equal(result.toHex(), "00000000000061a8");
});
it("decodeString", function () {
var result = openchain.encoding.decodeString(ByteBuffer.fromHex("414243"));
assert.equal(result, "ABC");
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var assert = require("assert");
var bitcore = require("bitcore-lib");
var ByteBuffer = require("protobufjs").ByteBuffer;
var Long = require("protobufjs").Long;
var q = require("q");
var openchain = require("../index");
var TransactionBuilder = openchain.TransactionBuilder;
var RecordKey = openchain.RecordKey;
var MutationSigner = openchain.MutationSigner;
var encoding = openchain.encoding;
describe("TransactionBuilder", function () {
it("constructor success", function () {
var builder = new TransactionBuilder(new ApiClientMock());
assert.deepEqual(builder.records, []);
assert.equal(builder.client.namespace.toHex(), "abcdef");
assert.equal(builder.metadata.toHex(), "");
});
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var openchain = require("../index");
var assert = require("assert");
var ByteBuffer = require("protobufjs").ByteBuffer;
var Long = require("protobufjs").Long;
var RecordKey = openchain.RecordKey;
describe('ApiClient', function () {
var client = new openchain.ApiClient("https://test.openchain.org/");
it('getRecord ByteBuffer', function () {
return client.getRecord(ByteBuffer.fromHex("0000")).then(function (result) {
assert.equal(result.key.toHex(), "0000");
assert.equal(result.value.toHex(), "");
assert.equal(result.version.toHex(), "");
});
});
it('getRecord string', function () {
return client.getRecord("/:DATA:info").then(function (result) {
var ProtoBuf = require("protobufjs"),
ByteBuffer = ProtoBuf.ByteBuffer, // ProtoBuf.js uses and also exposes ByteBuffer.js
Long = ProtoBuf.Long; // as well as Long.js (not used in this example)
// Option 1: Loading the .proto file directly
var builder = ProtoBuf.loadProtoFile("./json.proto"), // Creates the Builder
JS = builder.build("js"); // Returns just the 'js' namespace if that's all we need
// Option 2: Loading the .json file generated through 'proto2js json.proto > json.json'
var root = ProtoBuf.loadJsonFile("./json.json").build(), // Here we make the Builder return the root namespace
JS = root.js; // then we reference 'js' inside. Both is possible.
// Option 3: Loading the module generated through 'proto2js json.proto -commonjs=js > json.js'
var JS = require("./json.js"); // Returns what is specified with -commonjs[=XX] (omitted=root)
// `JS` now contains the js namespace from json.proto: Value, Array and Object
// This is how we use these classes:
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
"use strict";
module.exports.ApiClient = require("./lib/apiclient");
module.exports.Schema = require("./lib/schema");
module.exports.TransactionBuilder = require("./lib/transactionbuilder");
module.exports.LedgerPath = require("./lib/ledgerpath");
module.exports.RecordKey = require("./lib/recordkey");
module.exports.encoding = require("./lib/encoding");
module.exports.MutationSigner = require("./lib/mutationsigner");
module.exports.ByteBuffer = require("protobufjs").ByteBuffer;
module.exports.Long = require("protobufjs").Long;
// Create the "openchain" network
var bitcore = require("bitcore-lib");
var livenet = bitcore.Networks.get("livenet");
bitcore.Networks.add({
name: "openchain",
alias: "Openchain",
pubkeyhash: 76,
privatekey: livenet.privatekey,
scripthash: 78,
xpubkey: livenet.xpubkey,
xprivkey: livenet.xprivkey,
networkMagic: 0,
port: livenet.port,
dnsSeeds: livenet.dnsSeeds
});
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
"use strict";
var ByteBuffer = require("protobufjs").ByteBuffer;
var Long = require("protobufjs").Long;
/*
* Encodes a string into a byte buffer.
*
* @param {string} value The string being encoded.
* @return {!ByteBuffer} The encoded string.
*/
module.exports.encodeString = function (value) {
return ByteBuffer.wrap(value, "utf8", true);
};
/*
* Decodes a string from a byte buffer.
*
* @param {!ByteBuffer} buffer The buffer containing the string being decoded.
* @return {string} The decoded string.
var ProtoBuf = require("protobufjs"),
ByteBuffer = ProtoBuf.ByteBuffer, // ProtoBuf.js uses and also exposes ByteBuffer.js
Long = ProtoBuf.Long; // as well as Long.js (not used in this example)
// Option 1: Loading the .proto file directly
var builder = ProtoBuf.loadProtoFile("./json.proto"), // Creates the Builder
JS = builder.build("js"); // Returns just the 'js' namespace if that's all we need
// Option 2: Loading the .json file generated through 'proto2js json.proto > json.json'
var root = ProtoBuf.loadJsonFile("./json.json").build(), // Here we make the Builder return the root namespace
JS = root.js; // then we reference 'js' inside. Both is possible.
// Option 3: Loading the module generated through 'proto2js json.proto -commonjs=js > json.js'
var JS = require("./json.js"); // Returns what is specified with -commonjs[=XX] (omitted=root)
// `JS` now contains the js namespace from json.proto: Value, Array and Object
// This is how we use these classes:
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
"use strict";
var RecordKey = require("./recordkey");
var encoding = require("./encoding");
var ByteBuffer = require("protobufjs").ByteBuffer;
var Long = require("protobufjs").Long;
var httpinvoke = require("httpinvoke");
var bitcore = require("bitcore-lib");
var Schema = require("./schema.js");
/**
* Represents an Openchain client bound to a specific Openchain endpoint.
*
* @constructor
* @param {string} endpoint The base URL of the endpoint.
*/
function ApiClient(endpoint) {
if (endpoint.length > 0 && endpoint.slice(-1) != "/") {
endpoint += "/";
}
this.endpoint = endpoint;
'use strict';
const path = require('path');
const protoBuf = require('protobufjs');
const Long = protoBuf.Long;
var builder = protoBuf.newBuilder();
protoBuf.loadProtoFile(path.join(__dirname, '../proto/base.proto'));
protoBuf.loadProtoFile(path.join(__dirname, '../proto/filter.proto'), builder);
protoBuf.loadProtoFile(path.join(__dirname, '../proto/table.proto'), builder);
const Pb = builder.build('com.kingsoft.services.table.proto');
const utils = require('./base.js').utils;
const Encoder = require('./base.js').Encoder;
const Decoder = require('./base.js').Decoder;
const filter = require('./filter.js');
exports.checkResponse = function(pb) {
if (pb.code !== Pb.Code.kOk) {
throw utils.newError(pb.code, Decoder.code(pb.code), pb.msg);
}
};