forked from killerstorm/node-bitcoin-exit
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtx.js
38 lines (36 loc) · 1.03 KB
/
tx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var sys = require('sys');
require('buffertools');
var Module = require('./webservice').Module;
var bitcoin = require('bitcoinjs');
var Util = bitcoin.Util;
var Tx = exports.Tx = Module.define({
title: "Welcome to your webservice!",
name: "transaction service",
version: "0.1.0",
construct: function (params) {
this.node = params.node;
},
schema: {
'node': { type: bitcoin.Node, required: true }
}
});
Tx.method('send', {
schema: {
tx: { type: String, required: true }
},
handler: function (params, callback) {
// TODO: Call handleTx as if this transaction arrived with the network (or something like that :P)
var txBuf = new Buffer(params.tx.toString(), 'base64');
var message = bitcoin.Connection.prototype.parseMessage("tx", txBuf);
delete message.command;
var Transaction = bitcoin.schema.Transaction;
var tx = new Transaction(message);
this.node.sendTx(tx, function (err) {
if (err) {
callback(err);
return;
}
callback(null, {success: true});
});
}
});