dthorpe
11 years ago
19 changed files with 304 additions and 18 deletions
@ -0,0 +1,5 @@ |
|||
language: node_js |
|||
node_js: |
|||
- "0.10" |
|||
|
|||
script: "mocha" |
@ -0,0 +1,17 @@ |
|||
var bitcore = require('../bitcore'); |
|||
var Address = bitcore.Address; |
|||
var bitcoreUtil = bitcore.util; |
|||
var Script = bitcore.Script; |
|||
var network = bitcore.networks.livenet; |
|||
|
|||
|
|||
var script = ''; // write down your script here
|
|||
var s = Script.fromHumanReadable(script); |
|||
var hash = bitcoreUtil.sha256ripe160(s.getBuffer()); |
|||
var version = network.addressScript; |
|||
|
|||
var addr = new Address(version, hash); |
|||
var addrStr = addr.as('base58'); |
|||
|
|||
// This outputs the "address" of thescript
|
|||
console.log(addrStr); |
@ -0,0 +1,72 @@ |
|||
/** |
|||
* This is a simple script that will display network messages. |
|||
* It users the Peer / Connection classes * directly instead of |
|||
* relying on PeerManager. |
|||
*/ |
|||
|
|||
// replace by require('bitcore') if you use somewhere else
|
|||
var bitcore = require('../'); |
|||
|
|||
//bitcore.config.logger = 'debug';
|
|||
|
|||
var Peer = bitcore.Peer, |
|||
Connection = bitcore.Connection; |
|||
|
|||
var peer = new Peer('127.0.0.1', 8333); |
|||
|
|||
var socket = peer.createConnection(); |
|||
|
|||
var con = new Connection(socket, peer); |
|||
|
|||
con.on('error', function (msg) { |
|||
var peer = msg.peer, err = msg.err; |
|||
console.error('Error connecting to peer', peer.host + ':' + peer.port, '(' + err.message + ')'); |
|||
}); |
|||
|
|||
con.on('disconnect', function (msg) { |
|||
console.log('disconnect: ', msg); |
|||
}); |
|||
|
|||
con.on('connect', function (msg) { |
|||
console.log('Connected to %s', msg.peer.host + ':' + msg.peer.port); |
|||
}); |
|||
|
|||
/* Listen P2P messages */ |
|||
|
|||
// Make a log function available to all listeners
|
|||
// The log function is just like console.log except it prefixes
|
|||
// messages with [host:port]
|
|||
function listen (event_name, fn) { |
|||
con.on(event_name, function (event) { |
|||
fn(event, function () { |
|||
var args = Array.prototype.slice.call(arguments); |
|||
var str = args.shift(); |
|||
str = '[%s:%s] ' + str; |
|||
args = [ str, event.peer.host, event.peer.port ].concat(args); |
|||
console.log.apply(console, args); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
listen('getaddr', function (event, log) { |
|||
log('Received message getaddr'); |
|||
log(event); |
|||
}); |
|||
|
|||
listen('verack', function (event, log) { |
|||
log('Received message verack'); |
|||
}); |
|||
|
|||
listen('version', function (event, log) { |
|||
log('Received message version (%s)', event.message.version); |
|||
}); |
|||
|
|||
listen('addr', function (event, log) { |
|||
log('Received message addr (%s addresses)', event.message.addrs.length); |
|||
}); |
|||
|
|||
listen('inv', function (event, log) { |
|||
log('Received message inv (%s invs)', event.message.count); |
|||
console.log(event.message.invs); |
|||
}); |
|||
|
@ -0,0 +1 @@ |
|||
Run `node browser/build.js -a` in the repository's root directory before using those examples. |
@ -1,12 +1,13 @@ |
|||
<!DOCTYPE html> |
|||
<html> |
|||
<body> |
|||
<script src="../browser/bundle.js"></script> |
|||
<script src="../../browser/bundle.js"></script> |
|||
<pre id="console"></pre> |
|||
<script> |
|||
var bitcore = require('bitcore'); |
|||
var Address = bitcore.Address; |
|||
var a = new Address('1KerhGhLn3SYBEQwby7VyVMWf16fXQUj5d'); |
|||
console.log('1KerhGhLn3SYBEQwby7VyVMWf16fXQUj5d is valid? '+a.isValid()); |
|||
document.getElementById('console').innerHTML = '1KerhGhLn3SYBEQwby7VyVMWf16fXQUj5d is valid? '+a.isValid(); |
|||
</script> |
|||
</body> |
|||
</html> |
@ -0,0 +1,52 @@ |
|||
<!DOCTYPE html> |
|||
<html> |
|||
<head> |
|||
<title>Mocha</title> |
|||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|||
<link rel="stylesheet" href="./node_modules/mocha/mocha.css" /> |
|||
</head> |
|||
<body> |
|||
<div id="mocha"></div> |
|||
<script src="./node_modules/mocha/mocha.js"></script> |
|||
<script src="./node_modules/chai/chai.js"></script> |
|||
<script>mocha.setup('bdd')</script> |
|||
<script>mocha.reporter('tap')</script> |
|||
<script src="./browser/bundle.js"></script> |
|||
<script src="./browser/testdata.js"></script> |
|||
<script src="test/adapter.js"></script> |
|||
|
|||
<script src="test/test.Address.js"></script> |
|||
<script src="test/test.basic.js"></script> |
|||
<script src="test/test.BIP32.js"></script> |
|||
<script src="test/test.Block.js"></script> |
|||
<script src="test/test.Bloom.js"></script> |
|||
<script src="test/test.Connection.js"></script> |
|||
<script src="test/test.EncodedData.js"></script> |
|||
<script src="test/test.Key.js"></script> |
|||
<script src="test/test.main.js"></script> |
|||
<script src="test/test.misc.js"></script> |
|||
<script src="test/test.Opcode.js"></script> |
|||
<script src="test/test.Peer.js"></script> |
|||
<script src="test/test.PeerManager.js"></script> |
|||
<script src="test/test.Point.js"></script> |
|||
<script src="test/test.PrivateKey.js"></script> |
|||
<script src="test/test.RpcClient.js"></script> |
|||
<script src="test/test.Script.js"></script> |
|||
<script src="test/test.ScriptInterpreter.js"></script> |
|||
<script src="test/test.sighash.js"></script> |
|||
<script src="test/test.SIN.js"></script> |
|||
<script src="test/test.SINKey.js"></script> |
|||
<script src="test/test.Transaction.js"></script> |
|||
<script src="test/test.TransactionBuilder.js"></script> |
|||
<script src="test/test.util.js"></script> |
|||
<script src="test/test.VersionedData.js"></script> |
|||
<script src="test/test.Wallet.js"></script> |
|||
<script src="test/test.WalletKey.js"></script> |
|||
<!-- |
|||
--> |
|||
<script> |
|||
mocha.run(); |
|||
</script> |
|||
</body> |
|||
</html> |
Loading…
Reference in new issue