Merge pull request #490 from viacoin/op_return
Implement check for OP_RETURN
This commit is contained in:
commit
0977a2c23b
20
examples/Opreturn.js
Normal file
20
examples/Opreturn.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
|
var bitcore = require('../bitcore');
|
||||||
|
var Address = bitcore.Address;
|
||||||
|
var coinUtil = bitcore.util;
|
||||||
|
var Script = bitcore.Script;
|
||||||
|
var network = bitcore.networks.testnet;
|
||||||
|
|
||||||
|
var script = 'OP_RETURN 58434c524e4748530000000000000000000000010000000005f5e100';
|
||||||
|
var s = Script.fromHumanReadable(script);
|
||||||
|
var result = (s.classify() == Script.TX_RETURN)
|
||||||
|
console.log("Is op_return:", result);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
@ -11,13 +11,15 @@ var TX_PUBKEY = 1;
|
|||||||
var TX_PUBKEYHASH = 2;
|
var TX_PUBKEYHASH = 2;
|
||||||
var TX_MULTISIG = 3;
|
var TX_MULTISIG = 3;
|
||||||
var TX_SCRIPTHASH = 4;
|
var TX_SCRIPTHASH = 4;
|
||||||
|
var TX_RETURN = 5;
|
||||||
|
|
||||||
var TX_TYPES = [
|
var TX_TYPES = [
|
||||||
'unknown',
|
'unknown',
|
||||||
'pubkey',
|
'pubkey',
|
||||||
'pubkeyhash',
|
'pubkeyhash',
|
||||||
'multisig',
|
'multisig',
|
||||||
'scripthash'
|
'scripthash',
|
||||||
|
'return'
|
||||||
];
|
];
|
||||||
|
|
||||||
function Script(buffer) {
|
function Script(buffer) {
|
||||||
@ -35,6 +37,7 @@ Script.TX_PUBKEY = TX_PUBKEY;
|
|||||||
Script.TX_PUBKEYHASH = TX_PUBKEYHASH;
|
Script.TX_PUBKEYHASH = TX_PUBKEYHASH;
|
||||||
Script.TX_MULTISIG = TX_MULTISIG;
|
Script.TX_MULTISIG = TX_MULTISIG;
|
||||||
Script.TX_SCRIPTHASH = TX_SCRIPTHASH;
|
Script.TX_SCRIPTHASH = TX_SCRIPTHASH;
|
||||||
|
Script.TX_RETURN = TX_RETURN;
|
||||||
|
|
||||||
Script.prototype.parse = function() {
|
Script.prototype.parse = function() {
|
||||||
this.chunks = [];
|
this.chunks = [];
|
||||||
@ -90,6 +93,12 @@ Script.prototype.isPubkey = function() {
|
|||||||
this.chunks[1] == Opcode.map.OP_CHECKSIG);
|
this.chunks[1] == Opcode.map.OP_CHECKSIG);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Script.prototype.isReturn = function() {
|
||||||
|
return (this.chunks.length == 2 &&
|
||||||
|
Buffer.isBuffer(this.chunks[1]) &&
|
||||||
|
this.chunks[0] == Opcode.map.OP_RETURN);
|
||||||
|
};
|
||||||
|
|
||||||
Script.prototype.isPubkeyHash = function() {
|
Script.prototype.isPubkeyHash = function() {
|
||||||
return (this.chunks.length == 5 &&
|
return (this.chunks.length == 5 &&
|
||||||
this.chunks[0] == Opcode.map.OP_DUP &&
|
this.chunks[0] == Opcode.map.OP_DUP &&
|
||||||
@ -282,6 +291,8 @@ Script.prototype.classify = function() {
|
|||||||
return TX_MULTISIG;
|
return TX_MULTISIG;
|
||||||
if (this.isPubkey())
|
if (this.isPubkey())
|
||||||
return TX_PUBKEY;
|
return TX_PUBKEY;
|
||||||
|
if (this.isReturn())
|
||||||
|
return TX_RETURN;
|
||||||
return TX_UNKNOWN;
|
return TX_UNKNOWN;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user