-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCBitcoin.xs
111 lines (87 loc) · 2.14 KB
/
CBitcoin.xs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <ccoin/hdkeys.h>
#include <assert.h>
#include <openssl/ripemd.h>
#include <ccoin/util.h>
#include <ccoin/base58.h>
#include <openssl/err.h>
#include <ccoin/cstr.h>
// just a dummy function
int dummy(int arg){
return 1;
}
SV* picocoin_ripemd_hash160(SV* x){
STRLEN len; //calculated via SvPV
uint8_t * xmsg = (uint8_t*) SvPV(x,len);
uint8_t md160[RIPEMD160_DIGEST_LENGTH];
bu_Hash160(md160,xmsg,len);
return newSVpv(md160,RIPEMD160_DIGEST_LENGTH);
}
SV* picocoin_base58_encode(SV* x){
STRLEN len; //calculated via SvPV
uint8_t * xmsg = (uint8_t*) SvPV(x,len);
cstring * ans = base58_encode(xmsg,(size_t) len);
int length = (ans->len)*sizeof(char);
char * answer = malloc(length);
//sprintf("%s",ans->str);
memcpy(answer,ans->str,length);
SV* ans_sv = newSVpv(answer,length);
cstr_free(ans, true);
return ans_sv;
//return answer;
/*int i;
char * fullans = malloc((1 + ans->len) * sizeof(char));
for(i=0;i<ans->len+1;i++){
fullans[i] = ans->str[i];
}
cstr_free(ans, true);
return fullans;
*/
}
SV* picocoin_base58_decode(char* x){
STRLEN len; //calculated via SvPV
//uint8_t * xmsg = (uint8_t*) SvPV(x,len);
cstring * ans = base58_decode(x);
return newSVpv(ans->str,ans->len);
/*int i;
char * fullans = malloc((1 + ans->len) * sizeof(char));
for(i=0;i<ans->len+1;i++){
fullans[i] = ans->str[i];
}
cstr_free(ans, true);
return fullans;
*/
}
#define crutch_stack_wrap(directive) do { \
PUSHMARK(SP); \
PUTBACK; \
directive; \
SPAGAIN; \
PUTBACK; \
} while(0)
MODULE = CBitcoin PACKAGE = CBitcoin
BOOT:
crutch_stack_wrap(boot_CBitcoin__CBHD(aTHX_ cv));
crutch_stack_wrap(boot_CBitcoin__Script(aTHX_ cv));
crutch_stack_wrap(boot_CBitcoin__TransactionInput(aTHX_ cv));
crutch_stack_wrap(boot_CBitcoin__TransactionOutput(aTHX_ cv));
crutch_stack_wrap(boot_CBitcoin__Transaction(aTHX_ cv));
crutch_stack_wrap(boot_CBitcoin__Block(aTHX_ cv));
PROTOTYPES: DISABLED
int
dummy (arg)
int arg
SV*
picocoin_base58_encode(x)
SV* x
SV*
picocoin_base58_decode(x)
char* x
SV*
picocoin_ripemd_hash160(x)
SV* x