Skip to content

Commit

Permalink
XBR helpers 3 (#522)
Browse files Browse the repository at this point in the history
* export hex helpers

* export xbrchannel
  • Loading branch information
om26er authored Jul 27, 2020
1 parent f1d64ab commit 5d14cbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion packages/autobahn-xbr/lib/autobahn-xbr.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var setProvider = async function(provider) {
await ethereum.setProvider(provider);
exports.xbrtoken = ethereum.xbrtoken;
exports.xbrnetwork = ethereum.xbrnetwork;
exports.xbrchannel = ethereum.xbrchannel;
};

exports.setProvider = setProvider;
Expand All @@ -61,8 +62,10 @@ exports.MemberLevel = ethereum.MemberLevel;
exports.NodeType = ethereum.NodeType;
exports.ActorType = ethereum.ActorType;

var util = require('./util.js');
let util = require('./util.js');

exports.uuid = util.uuid;
exports.pack_uint256 = util.pack_uint256;
exports.unpack_uint256 = util.unpack_uint256;
exports.with_0x = util.with_0x;
exports.without_0x = util.without_0x;
7 changes: 7 additions & 0 deletions packages/autobahn-xbr/lib/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ async function init_xbr() {
console.log('WARNING: The XBR smart contracts are not yet depoyed to public networks. Please set XBR_DEBUG_NETWORK_ADDR manually.');
exports.xbrnetwork = await XBRNetwork.at("0x254dffcd3277c0b1660f6d42efbb754edababc2b");
}

if ('XBR_DEBUG_CHANNEL_ADDR' in global && XBR_DEBUG_CHANNEL_ADDR) {
exports.xbrchannel = await XBRChannel.at(XBR_DEBUG_CHANNEL_ADDR);
} else {
console.log('WARNING: The XBR smart contracts are not yet depoyed to public networks. Please set XBR_DEBUG_CHANNEL_ADDR manually.');
exports.xbrchannel = await XBRChannel.at("0x670497A012322B99a5C18B8463940996141Cb952");
}
}

exports.XBRToken = XBRToken;
Expand Down
9 changes: 4 additions & 5 deletions packages/autobahn-xbr/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function pack_uint256 (value) {


function unpack_uint256 (value) {
// FIXME: wont work in browser ?
let buffer = Buffer.from(value);
return buffer.readUIntBE(0, value.length);
}
Expand Down Expand Up @@ -88,7 +87,7 @@ function uuid (value) {
}


function without0x (string) {
function without_0x (string) {
assert(typeof string === 'string', 'Input must be a string')

if (string.startsWith("0x")) {
Expand All @@ -99,7 +98,7 @@ function without0x (string) {
}


function with0x (string) {
function with_0x (string) {
assert(typeof string === 'string', 'Input must be a string')

if (!string.startsWith("0x")) {
Expand All @@ -113,5 +112,5 @@ function with0x (string) {
exports.pack_uint256 = pack_uint256;
exports.unpack_uint256 = unpack_uint256;
exports.uuid = uuid;
exports.without0x = without0x;
exports.with0x = with0x;
exports.without_0x = without_0x;
exports.with_0x = with_0x;

0 comments on commit 5d14cbb

Please sign in to comment.