-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcom_ravencoin_core_BRCoreTransactionOutput.c
More file actions
executable file
·131 lines (113 loc) · 4.56 KB
/
com_ravencoin_core_BRCoreTransactionOutput.c
File metadata and controls
executable file
·131 lines (113 loc) · 4.56 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Created by Ed Gamble on 1/31/2018
// Copyright (c) 2018 ravencoin LLC.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "CoreJni.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <BRTransaction.h>
#include "com_ravencoin_core_BRCoreTransactionOutput.h"
/*
* Class: com_ravencoin_core_BRCoreTransactionOutput
* Method: createTransactionOutput
* Signature: (J[B)J
*/
JNIEXPORT jlong JNICALL
Java_com_ravencoin_core_BRCoreTransactionOutput_createTransactionOutput
(JNIEnv *env, jclass thisClass,
jlong amount,
jbyteArray scriptByteArray) {
BRTxOutput *output = (BRTxOutput *) calloc(1, sizeof(BRTxOutput));
// script
output->script = NULL;
size_t scriptLen = (size_t) (*env)->GetArrayLength(env, scriptByteArray);
const uint8_t *script = (const uint8_t *)
(0 == scriptLen
? NULL
: (*env)->GetByteArrayElements(env, scriptByteArray, 0));
BRTxOutputSetScript(output, script, scriptLen);
output->amount = (uint64_t) amount;
return (jlong) output;
}
/*
* Class: com_ravencoin_core_BRCoreTransactionOutput
* Method: getAddress
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_com_ravencoin_core_BRCoreTransactionOutput_getAddress
(JNIEnv *env, jobject thisObject) {
BRTxOutput *output = (BRTxOutput *) getJNIReference (env, thisObject);
size_t addressLen = sizeof (output->address);
char address[1 + addressLen];
memcpy (address, output->address, addressLen);
address[addressLen] = '\0';
return (*env)->NewStringUTF (env, address);
}
/*
* Class: com_ravencoin_core_BRCoreTransactionOutput
* Method: setAddress
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL
Java_com_ravencoin_core_BRCoreTransactionOutput_setAddress
(JNIEnv *env, jobject thisObject, jstring addressObject) {
BRTxOutput *output = (BRTxOutput *) getJNIReference (env, thisObject);
size_t addressLen = sizeof (output->address);
size_t addressDataLen = (size_t) (*env)->GetStringLength (env, addressObject);
const jchar *addressData = (*env)->GetStringChars (env, addressObject, 0);
assert (addressDataLen <= addressLen);
memset (output->address, '\0', addressLen);
memcpy (output->address, addressData, addressDataLen);
}
/*
* Class: com_ravencoin_core_BRCoreTransactionOutput
* Method: getAmount
* Signature: ()J
*/
JNIEXPORT jlong JNICALL
Java_com_ravencoin_core_BRCoreTransactionOutput_getAmount
(JNIEnv *env, jobject thisObject) {
BRTxOutput *output = (BRTxOutput *) getJNIReference (env, thisObject);
return (jlong) output->amount;
}
/*
* Class: com_ravencoin_core_BRCoreTransactionOutput
* Method: setAmount
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_ravencoin_core_BRCoreTransactionOutput_setAmount
(JNIEnv *env, jobject thisObject, jlong amount) {
BRTxOutput *output = (BRTxOutput *) getJNIReference (env, thisObject);
output->amount = (uint64_t) amount;
}
/*
* Class: com_ravencoin_core_BRCoreTransactionOutput
* Method: getScript
* Signature: ()[B
*/
JNIEXPORT jbyteArray JNICALL Java_com_ravencoin_core_BRCoreTransactionOutput_getScript
(JNIEnv *env, jobject thisObject) {
BRTxOutput *output = (BRTxOutput *) getJNIReference (env, thisObject);
jbyteArray scriptByteArray = (*env)->NewByteArray (env, output->scriptLen);
(*env)->SetByteArrayRegion (env, scriptByteArray, 0, output->scriptLen,
(const jbyte *) output->script);
return scriptByteArray;
}