Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Fist attempt at TX_MULTISIG
Browse files Browse the repository at this point in the history
  • Loading branch information
aido committed Jan 11, 2014
1 parent 2d09fe0 commit d663587
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
7 changes: 7 additions & 0 deletions include/ccoin/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,17 @@ struct bscript_op {
struct const_buffer data; /* associated data, if any */
};

struct bscript_multisig {
struct bscript_op *nKeys;
struct bscript_op *pubKeys;
struct bscript_op *nSigs;
};

struct bscript_addr {
enum txnouttype txtype;
GList *pub; /* of struct buffer */
GList *pubhash; /* of struct buffer */
GList *multisig; /* of struct bscript_multisig */
};

extern const char *GetOpName(enum opcodetype opcode);
Expand Down
42 changes: 40 additions & 2 deletions lib/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ static const unsigned char stdscr_pubkey[] = {
static const unsigned char stdscr_pubkeyhash[] = {
OP_DUP, OP_HASH160, OP_PUBKEYHASH, OP_EQUALVERIFY, OP_CHECKSIG,
};

static const unsigned char stdscr_multisig[] = {
OP_SMALLINTEGER, OP_PUBKEYS, OP_SMALLINTEGER, OP_CHECKMULTISIG
};
static const struct {
enum txnouttype txtype;
size_t len;
const unsigned char *script;
} std_scripts[] = {
{ TX_PUBKEY, sizeof(stdscr_pubkey), stdscr_pubkey, },
{ TX_PUBKEYHASH, sizeof(stdscr_pubkeyhash), stdscr_pubkeyhash, },
{ TX_MULTISIG, sizeof(stdscr_multisig), stdscr_multisig, },
};

bool bsp_getop(struct bscript_op *op, struct bscript_parser *bp)
Expand Down Expand Up @@ -120,6 +123,26 @@ static bool bsp_match_op(const struct bscript_op *op, unsigned char template)
{
switch (template) {

case OP_PUBKEYS:
if (!is_bsp_pushdata(op->op))
return false;
if (op->data.len < 33 || op->data.len > 120)
return false;

GPtrArray *ops = bsp_parse_all(&op->data, op->data.len);
if (!ops)
return false;

unsigned int i;
for (i = 0; i < ops->len; i++) {
struct bscript_op *op1;

op1 = g_ptr_array_index(ops, i);
if (op1->data.len < 33 || op1->data.len > 120)
return false;
}
return true;

case OP_PUBKEY:
if (!is_bsp_pushdata(op->op))
return false;
Expand All @@ -133,8 +156,14 @@ static bool bsp_match_op(const struct bscript_op *op, unsigned char template)
if (op->data.len != 20)
return false;
return true;

case OP_SMALLINTEGER:
if (!is_bsp_pushdata(op->op))
return false;
/* TODO: Finish code */
return true;

default:
default:
if (is_bsp_pushdata(op->op))
return false;

Expand Down Expand Up @@ -201,6 +230,15 @@ bool bsp_addr_parse(struct bscript_addr *addr,
addr->pubhash = g_list_append(addr->pub, buf);
break;
}

case TX_MULTISIG: {
struct bscript_multisig *multisig;
multisig->nKeys = g_ptr_array_index(ops, 0);
multisig->pubKeys = g_ptr_array_index(ops, 1);
multisig->nSigs = g_ptr_array_index(ops, 2);
addr->multisig = g_list_append(addr->multisig, multisig);
break;
}

default:
/* do nothing */
Expand Down
6 changes: 4 additions & 2 deletions lib/script_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <ccoin/key.h>
#include <ccoin/core.h>
#include <ccoin/buint.h>
#include <ccoin/key.h>
#include <ccoin/util.h>

static bool sign1(const bu160_t *key_id, struct bp_keystore *ks,
Expand Down Expand Up @@ -90,8 +89,11 @@ bool bp_script_sign(struct bp_keystore *ks, const GString *fromPubKey,
goto out;
break;

case TX_SCRIPTHASH: /* TODO; not supported yet */
case TX_MULTISIG:
/* TODO: Finish code */
goto out;

case TX_SCRIPTHASH: /* TODO; not supported yet */
goto out;

case TX_NONSTANDARD: /* unknown script type, cannot sign */
Expand Down

0 comments on commit d663587

Please sign in to comment.