Skip to content

Commit ce93f74

Browse files
committed
3.5.6.3-leisure
Add more data support to createrawtransaction.
1 parent 4f40bf1 commit ce93f74

File tree

6 files changed

+591
-5
lines changed

6 files changed

+591
-5
lines changed

Makefile.Debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#############################################################################
22
# Makefile for building: gridcoinresearch
3-
# Generated by qmake (2.01a) (Qt 4.8.4) on: Fri Apr 22 17:08:10 2016
3+
# Generated by qmake (2.01a) (Qt 4.8.4) on: Sat Apr 23 10:25:02 2016
44
# Project: gridcoinresearch.pro
55
# Template: app
66
#############################################################################

Makefile.Release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#############################################################################
22
# Makefile for building: gridcoinresearch
3-
# Generated by qmake (2.01a) (Qt 4.8.4) on: Fri Apr 22 17:08:10 2016
3+
# Generated by qmake (2.01a) (Qt 4.8.4) on: Sat Apr 23 10:25:02 2016
44
# Project: gridcoinresearch.pro
55
# Template: app
66
#############################################################################

src/clientversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define CLIENT_VERSION_MAJOR 3
1010
#define CLIENT_VERSION_MINOR 5
1111
#define CLIENT_VERSION_REVISION 6
12-
#define CLIENT_VERSION_BUILD 2
12+
#define CLIENT_VERSION_BUILD 3
1313

1414
// Converts the parameter X to a string after macro replacement on X has been performed.
1515
// Don't merge these into one macro!

src/rpcrawtransaction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "main.h"
1313
#include "net.h"
1414
#include "wallet.h"
15-
15+
//#include "univalue.h"
1616
#include "upgrader.h"
1717

1818
using namespace std;
@@ -467,6 +467,7 @@ Value createrawtransaction(const Array& params, bool fHelp)
467467

468468
Array inputs = params[0].get_array();
469469
Object sendTo = params[1].get_obj();
470+
//UniValue sendTo2 = params[1].get_obj();
470471

471472
CTransaction rawTx;
472473

@@ -497,7 +498,7 @@ Value createrawtransaction(const Array& params, bool fHelp)
497498
{
498499
if (s.name_ == "data")
499500
{
500-
std::vector<unsigned char> data = ParseHexV(params[1],"Data");
501+
std::vector<unsigned char> data = ParseHexV(s.value_,"Data");
501502
CTxOut out(0, CScript() << OP_RETURN << data);
502503
rawTx.vout.push_back(out);
503504
}

src/univalue.cpp

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
// Copyright 2014 BitPay Inc.
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <stdint.h>
6+
#include <ctype.h>
7+
#include <iomanip>
8+
#include <sstream>
9+
#include <stdexcept> // std::runtime_error
10+
11+
#include "univalue.h"
12+
13+
#include "utilstrencodings.h" // ParseXX
14+
15+
using namespace std;
16+
17+
const UniValue NullUniValue;
18+
19+
void UniValue::clear()
20+
{
21+
typ = VNULL;
22+
val.clear();
23+
keys.clear();
24+
values.clear();
25+
}
26+
27+
bool UniValue::setNull()
28+
{
29+
clear();
30+
return true;
31+
}
32+
33+
bool UniValue::setBool(bool val_)
34+
{
35+
clear();
36+
typ = VBOOL;
37+
if (val_)
38+
val = "1";
39+
return true;
40+
}
41+
42+
static bool validNumStr(const string& s)
43+
{
44+
string tokenVal;
45+
unsigned int consumed;
46+
enum jtokentype tt = getJsonToken(tokenVal, consumed, s.c_str());
47+
return (tt == JTOK_NUMBER);
48+
}
49+
50+
bool UniValue::setNumStr(const string& val_)
51+
{
52+
if (!validNumStr(val_))
53+
return false;
54+
55+
clear();
56+
typ = VNUM;
57+
val = val_;
58+
return true;
59+
}
60+
61+
bool UniValue::setInt(uint64_t val)
62+
{
63+
string s;
64+
ostringstream oss;
65+
66+
oss << val;
67+
68+
return setNumStr(oss.str());
69+
}
70+
71+
bool UniValue::setInt(int64_t val)
72+
{
73+
string s;
74+
ostringstream oss;
75+
76+
oss << val;
77+
78+
return setNumStr(oss.str());
79+
}
80+
81+
bool UniValue::setFloat(double val)
82+
{
83+
string s;
84+
ostringstream oss;
85+
86+
oss << std::setprecision(16) << val;
87+
88+
bool ret = setNumStr(oss.str());
89+
typ = VNUM;
90+
return ret;
91+
}
92+
93+
bool UniValue::setStr(const string& val_)
94+
{
95+
clear();
96+
typ = VSTR;
97+
val = val_;
98+
return true;
99+
}
100+
101+
bool UniValue::setArray()
102+
{
103+
clear();
104+
typ = VARR;
105+
return true;
106+
}
107+
108+
bool UniValue::setObject()
109+
{
110+
clear();
111+
typ = VOBJ;
112+
return true;
113+
}
114+
115+
bool UniValue::push_back(const UniValue& val)
116+
{
117+
if (typ != VARR)
118+
return false;
119+
120+
values.push_back(val);
121+
return true;
122+
}
123+
124+
bool UniValue::push_backV(const std::vector<UniValue>& vec)
125+
{
126+
if (typ != VARR)
127+
return false;
128+
129+
values.insert(values.end(), vec.begin(), vec.end());
130+
131+
return true;
132+
}
133+
134+
bool UniValue::pushKV(const std::string& key, const UniValue& val)
135+
{
136+
if (typ != VOBJ)
137+
return false;
138+
139+
keys.push_back(key);
140+
values.push_back(val);
141+
return true;
142+
}
143+
144+
bool UniValue::pushKVs(const UniValue& obj)
145+
{
146+
if (typ != VOBJ || obj.typ != VOBJ)
147+
return false;
148+
149+
for (unsigned int i = 0; i < obj.keys.size(); i++) {
150+
keys.push_back(obj.keys[i]);
151+
values.push_back(obj.values[i]);
152+
}
153+
154+
return true;
155+
}
156+
157+
int UniValue::findKey(const std::string& key) const
158+
{
159+
for (unsigned int i = 0; i < keys.size(); i++) {
160+
if (keys[i] == key)
161+
return (int) i;
162+
}
163+
164+
return -1;
165+
}
166+
167+
bool UniValue::checkObject(const std::map<std::string,UniValue::VType>& t)
168+
{
169+
for (std::map<std::string,UniValue::VType>::const_iterator it = t.begin();
170+
it != t.end(); it++) {
171+
int idx = findKey(it->first);
172+
if (idx < 0)
173+
return false;
174+
175+
if (values[idx].getType() != it->second)
176+
return false;
177+
}
178+
179+
return true;
180+
}
181+
182+
const UniValue& UniValue::operator[](const std::string& key) const
183+
{
184+
if (typ != VOBJ)
185+
return NullUniValue;
186+
187+
int index = findKey(key);
188+
if (index < 0)
189+
return NullUniValue;
190+
191+
return values[index];
192+
}
193+
194+
const UniValue& UniValue::operator[](unsigned int index) const
195+
{
196+
if (typ != VOBJ && typ != VARR)
197+
return NullUniValue;
198+
if (index >= values.size())
199+
return NullUniValue;
200+
201+
return values[index];
202+
}
203+
204+
const char *uvTypeName(UniValue::VType t)
205+
{
206+
switch (t) {
207+
case UniValue::VNULL: return "null";
208+
case UniValue::VBOOL: return "bool";
209+
case UniValue::VOBJ: return "object";
210+
case UniValue::VARR: return "array";
211+
case UniValue::VSTR: return "string";
212+
case UniValue::VNUM: return "number";
213+
}
214+
215+
// not reached
216+
return NULL;
217+
}
218+
219+
const UniValue& find_value( const UniValue& obj, const std::string& name)
220+
{
221+
for (unsigned int i = 0; i < obj.keys.size(); i++)
222+
{
223+
if( obj.keys[i] == name )
224+
{
225+
return obj.values[i];
226+
}
227+
}
228+
229+
return NullUniValue;
230+
}
231+
232+
std::vector<std::string> UniValue::getKeys() const
233+
{
234+
if (typ != VOBJ)
235+
throw std::runtime_error("JSON value is not an object as expected");
236+
return keys;
237+
}
238+
239+
std::vector<UniValue> UniValue::getValues() const
240+
{
241+
if (typ != VOBJ && typ != VARR)
242+
throw std::runtime_error("JSON value is not an object or array as expected");
243+
return values;
244+
}
245+
246+
bool UniValue::get_bool() const
247+
{
248+
if (typ != VBOOL)
249+
throw std::runtime_error("JSON value is not a boolean as expected");
250+
return getBool();
251+
}
252+
253+
std::string UniValue::get_str() const
254+
{
255+
if (typ != VSTR)
256+
throw std::runtime_error("JSON value is not a string as expected");
257+
return getValStr();
258+
}
259+
260+
int UniValue::get_int() const
261+
{
262+
if (typ != VNUM)
263+
throw std::runtime_error("JSON value is not an integer as expected");
264+
int32_t retval;
265+
if (!ParseInt32(getValStr(), &retval))
266+
throw std::runtime_error("JSON integer out of range");
267+
return retval;
268+
}
269+
270+
int64_t UniValue::get_int64() const
271+
{
272+
if (typ != VNUM)
273+
throw std::runtime_error("JSON value is not an integer as expected");
274+
int64_t retval;
275+
if (!ParseInt64(getValStr(), &retval))
276+
throw std::runtime_error("JSON integer out of range");
277+
return retval;
278+
}
279+
280+
double UniValue::get_real() const
281+
{
282+
if (typ != VNUM)
283+
throw std::runtime_error("JSON value is not a number as expected");
284+
double retval;
285+
if (!ParseDouble(getValStr(), &retval))
286+
throw std::runtime_error("JSON double out of range");
287+
return retval;
288+
}
289+
290+
const UniValue& UniValue::get_obj() const
291+
{
292+
if (typ != VOBJ)
293+
throw std::runtime_error("JSON value is not an object as expected");
294+
return *this;
295+
}
296+
297+
const UniValue& UniValue::get_array() const
298+
{
299+
if (typ != VARR)
300+
throw std::runtime_error("JSON value is not an array as expected");
301+
return *this;
302+
}

0 commit comments

Comments
 (0)