more promising conversion functions.

This commit is contained in:
Christopher Jeffrey 2014-10-01 16:42:07 -07:00
parent 8c411db79a
commit 1913237a3f

View File

@ -2368,7 +2368,7 @@ NAN_METHOD(WalletImportKey) {
pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value' pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value'
// Do this on the threadpool instead. // Do this on the threadpool instead.
// if (fRescan) { // if (data->fRescan) {
// pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true); // pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true);
// } // }
} }
@ -2676,8 +2676,11 @@ hextx_to_ctx(std::string tx_hex, CTransaction& ctx) {
} }
} }
#if 1 #if 0
/* /*
NOTES:
class CBlockHeader class CBlockHeader
{ {
public: public:
@ -2727,79 +2730,61 @@ public:
static inline void static inline void
jsblock_to_cblock(const Local<Object> obj, CBlock& block, CBlockIndex* blockindex) { jsblock_to_cblock(const Local<Object> obj, CBlock& block, CBlockIndex* blockindex) {
// block.GetHash().GetHex().c_str() = obj->Get(NanNew<String>("hash"))->ToString();
// txGen.GetDepthInMainChain()= obj->Get(NanNew<String>("confirmations"))->IntegerValue();
// (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) =
// obj->Get(NanNew<String>("size"))->IntegerValue();
if (blockindex) { if (blockindex) {
blockindex->nHeight = obj->Get(NanNew<String>("height"))->IntegerValue(); blockindex->nHeight = obj->Get(NanNew<String>("height"))->IntegerValue();
} }
block->nVersion = (int)obj->Get(NanNew<String>("version"))->IntegerValue(); block->nVersion = (int)obj->Get(NanNew<String>("version"))->IntegerValue();
String::Utf8Value mhash__(obj->Get(NanNew<String>("previousblockhash"))->ToString()); String::AsciiValue mhash__(obj->Get(NanNew<String>("previousblockhash"))->ToString());
std::string mhash_ = *mhash__; std::string mhash_ = *mhash__;
if (mhash_[1] != 'x') mhash_ = "0x" + mhash_; if (mhash_[1] != 'x') mhash_ = "0x" + mhash_;
uint256 mhash(mhash_); uint256 mhash(mhash_);
block->hashMerkleRoot = mhash; block->hashMerkleRoot = mhash;
// Local<Array> merkletree = Local<Array>::Cast(obj->Get("merkletree"));
// block->vMerkleTree = NULL;
Local<Array> txs = Local<Array>::Cast(obj->Get("tx")); Local<Array> txs = Local<Array>::Cast(obj->Get("tx"));
for (int ti = 0; ti < txs->Length(); ti++) { for (int ti = 0; ti < txs->Length(); ti++) {
Local<Object> entry = txs->Get(ti); Local<Object> entry = Local<Object>::Cast(txs->Get(ti));
CTransaction tx; CTransaction tx;
Local<Object> entry = NanNew<Object>(); Local<Object> entry = NanNew<Object>();
// CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
// ssTx << tx;
// std::string strHex = HexStr(ssTx.begin(), ssTx.end());
// strHex = entry->Get(NanNew<String>("hex"))->ToString();
// tx.GetHash().GetHex() = entry->Get(NanNew<String>("txid"))->ToString();
tx.nVersion = entry->Get(NanNew<String>("version"))->IntegerValue(); tx.nVersion = entry->Get(NanNew<String>("version"))->IntegerValue();
tx.nLockTime = entry->Get(NanNew<String>("locktime"))->IntegerValue(); tx.nLockTime = entry->Get(NanNew<String>("locktime"))->IntegerValue();
Local<Array> vin = Local<Array>::Cast(entry->Get("vin")); Local<Array> vin = Local<Array>::Cast(entry->Get("vin"));
for (int vi = 0; vi < vin->Length(); vi++) { for (int vi = 0; vi < vin->Length(); vi++) {
CTxIn txin; CTxIn txin;
Local<Object> in = vin->Get(vi); Local<Object> in = Local<Object>::Cast(vin->Get(vi));
std::string shash;
if (in->Get(NanNew<String>("coinbase"))->IsString()) { if (in->Get(NanNew<String>("coinbase"))->IsString()) {
String::Utf8Value shash_(obj->Get(NanNew<String>("coinbase"))->ToString()); String::AsciiValue shash_(obj->Get(NanNew<String>("coinbase"))->ToString());
std::string shash = *shash_; shash = *shash_;
CScript scriptSig(shash);
txin.scriptSig = scriptSig;
// HexStr(txin.scriptSig.begin(), txin.scriptSig.end()) = in->Get(NanNew<String>("coinbase"))->ToString();
} else { } else {
String::Utf8Value shash_(obj->Get(NanNew<String>("scriptSig"))->ToString()); String::AsciiValue shash_(obj->Get(NanNew<String>("scriptSig"))->ToString());
std::string shash = *shash_; shash = *shash_;
CScript scriptSig(shash);
txin.scriptSig = scriptSig;
// txin.prevout.hash.GetHex() = in->Get(NanNew<String>("txid"))->ToString();
String::Utf8Value phash__(in->Get(NanNew<String>("txid"))->ToString());
std::string phash_ = *phash__;
if (phash_[1] != 'x') phash_ = "0x" + phash_;
uint256 phash(phash_);
txin.prevout.hash = phash;
txin.prevout.n = (boost::int64_t)in->Get(NanNew<String>("vout"))->IntegerValue();
// Local<Object> o = in->Get(NanNew<String>("scriptSig"));
// txin.scriptSig.ToString() = o->Get(NanNew<String>("asm"))->ToString();
// HexStr(txin.scriptSig.begin(), txin.scriptSig.end()) = o->Get(NanNew<String>("hex"))->ToString();
} }
(boost::int64_t)txin.nSequence = in->Get(NanNew<String>("sequence"))->IntegerValue(); CScript scriptSig(shash);
txin.scriptSig = scriptSig;
String::AsciiValue phash__(in->Get(NanNew<String>("txid"))->ToString());
std::string phash_ = *phash__;
if (phash_[1] != 'x') phash_ = "0x" + phash_;
uint256 phash(phash_);
txin.prevout.hash = phash;
txin.prevout.n = (boost::int64_t)in->Get(NanNew<String>("vout"))->IntegerValue();
txin.nSequence = (boost::int64_t)in->Get(NanNew<String>("sequence"))->IntegerValue();
tx.vin.push_back(txin);
} }
Local<Array> vout = Local<Array>::Cast(entry->Get("vout")); Local<Array> vout = Local<Array>::Cast(entry->Get("vout"));
for (unsigned int vo = 0; vo < vout->Length(); vo++) { for (unsigned int vo = 0; vo < vout->Length(); vo++) {
const CTxOut txout; const CTxOut txout;
Local<Object> out = vout->Get(vo); Local<Object> out = Local<Object>::Cast(vout->Get(vo));
txout.nValue = (int64_t)out->Get(NanNew<String>("value"))->IntegerValue(); txout.nValue = (int64_t)out->Get(NanNew<String>("value"))->IntegerValue();
// vo = (boost::int64_t)out->Get(NanNew<String>("n"))->IntegerValue();
Local<Object> spk = Local<Object>::Cast(in->Get(NanNew<String>("scriptPubKey")));
String::Utf8Value phash__(in->Get(NanNew<String>("scriptPubKey"))->Get(NanNew<String>("hex"))); String::AsciiValue phash__(spk->Get(NanNew<String>("hex")));
std::string phash_ = *phash__; std::string phash_ = *phash__;
if (phash_[1] != 'x') phash_ = "0x" + phash_; if (phash_[1] != 'x') phash_ = "0x" + phash_;
uint256 phash(phash_); uint256 phash(phash_);
@ -2807,140 +2792,73 @@ jsblock_to_cblock(const Local<Object> obj, CBlock& block, CBlockIndex* blockinde
txout.scriptPubKey = scriptPubKey; txout.scriptPubKey = scriptPubKey;
/* tx.vout.push_back(txout);
Local<Object> o = out->Get(NanNew<String>("scriptPubKey"));
{
CScript scriptPubKey;
Local<Object> out = o;
bool fIncludeHex = true;
txnouttype type;
vector<CTxDestination> addresses;
int nRequired;
scriptPubKey.ToString() = out->Get(NanNew<String>("asm"))->ToString();
if (fIncludeHex) {
HexStr(scriptPubKey.begin(), scriptPubKey.end()) = out->Set(NanNew<String>("hex"))->ToString();
}
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
GetTxnOutputType(type) = out->Set(NanNew<String>("type"))->ToString();
} else {
nRequired = out->Set(NanNew<String>("reqSigs"))->IntegerValue();
GetTxnOutputType(type) = out->Set(NanNew<String>("type"))->ToString();
Local<Array> a = Local<Array>::Cast(out->Get("addresses"));
for (int ai = 0; ai < a->Length(); ai++) {
CTxDestination addr;
CBitcoinAddress(addr).ToString() = a->Get(ai)->ToString();
}
}
}
*/
}
if (entry->Get(NanNew<String>("blockhash"))->IsString()) {
const uint256 hashBlock;
hashBlock.GetHex() = entry->Get(NanNew<String>("blockhash"))->ToString();
if (entry->Get(NanNew<String>("time"))->IsNumber()) {
1 + chainActive.Height() - pindex->nHeight = entry->Get(NanNew<String>("confirmations"))->IntegerValue();
(boost::int64_t)pindex->nTime = entry->Get(NanNew<String>("time"))->IntegerValue();
(boost::int64_t)pindex->nTime = entry->Get(NanNew<String>("blocktime"))->IntegerValue();
} else {
0 = entry->Get(NanNew<String>("confirmations"))->IntegerValue();
}
} }
block->vtx.push_back(tx);
} }
block->nTime = (unsigned int)obj->Get(NanNew<String>("time"))->IntegerValue(); block->nTime = (unsigned int)obj->Get(NanNew<String>("time"))->IntegerValue();
block->nNonce = (unsigned int)obj->Get(NanNew<String>("nonce"))->IntegerValue(); block->nNonce = (unsigned int)obj->Get(NanNew<String>("nonce"))->IntegerValue();
block->nBits = (unsigned int)obj->Get(NanNew<String>("bits"))->IntegerValue(); block->nBits = (unsigned int)obj->Get(NanNew<String>("bits"))->IntegerValue();
// GetDifficulty(blockindex) = obj->Get(NanNew<String>("difficulty"))->IntegerValue();
// blockindex->nChainWork.GetHex() = obj->Get(NanNew<String>("chainwork"))->ToString();
if (obj->Get(NanNew<String>("previousblockhash"))->IsString()) { if (obj->Get(NanNew<String>("previousblockhash"))->IsString()) {
String::Utf8Value hash__(obj->Get(NanNew<String>("previousblockhash"))->ToString()); String::AsciiValue hash__(obj->Get(NanNew<String>("previousblockhash"))->ToString());
std::string hash_ = *hash__; std::string hash_ = *hash__;
if (hash_[1] != 'x') hash_ = "0x" + hash_; if (hash_[1] != 'x') hash_ = "0x" + hash_;
uint256 hash(hash_); uint256 hash(hash_);
// if (blockindex) {
// blockindex->pprev->GetBlockHash().GetHex() = obj->Get(NanNew<String>("previousblockhash"))->ToString();
// }
block->hashPrevBlock = hash; block->hashPrevBlock = hash;
} else { } else {
uint256 hash(std::string("0000000000000000000000000000000000000000000000000000000000000000")); uint256 hash(std::string("0000000000000000000000000000000000000000000000000000000000000000"));
block->hashPrevBlock = hash; block->hashPrevBlock = hash;
} }
// if (obj->Get(NanNew<String>("nextblockhash"))->IsString()) {
// CBlockIndex pnext;
// CBlockIndex *pnext = chainActive.Next(blockindex);
// pnext->GetBlockHash().GetHex() = obj->Get(NanNew<String>("nextblockhash"))->ToString();
// }
} }
static inline void static inline void
jstx_to_ctx(const Local<Object> entry, CTransaction& tx, uint256 hashBlock) { jstx_to_ctx(const Local<Object> entry, CTransaction& tx, uint256 hashBlock) {
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << tx;
std::string strHex = HexStr(ssTx.begin(), ssTx.end());
strHex = entry->Get(NanNew<String>("hex"), NanNew<String>(strHex))->ToString();
tx.GetHash().GetHex() = entry->Get(NanNew<String>("txid"))->ToString();
tx.nVersion = entry->Get(NanNew<String>("version"))->IntegerValue(); tx.nVersion = entry->Get(NanNew<String>("version"))->IntegerValue();
tx.nLockTime = entry->Get(NanNew<String>("locktime"))->IntegerValue(); tx.nLockTime = entry->Get(NanNew<String>("locktime"))->IntegerValue();
Local<Array> vin = Local<Array>::Cast(entry->Get("vin")); Local<Array> vin = Local<Array>::Cast(entry->Get("vin"));
for (int vi = 0; vi < vin->Length(); vi++) { for (int vi = 0; vi < vin->Length(); vi++) {
const CTxIn txin; CTxIn txin;
Local<Object> in = vin->Get(vi); Local<Object> in = Local<Object>::Cast(vin->Get(vi));
if (in->Get(NanNew<String>("coinbase")->IsString()) { std::string shash;
HexStr(txin.scriptSig.begin(), txin.scriptSig.end()) = in->Get(NanNew<String>("coinbase"))->ToString(); if (in->Get(NanNew<String>("coinbase"))->IsString()) {
String::AsciiValue shash_(obj->Get(NanNew<String>("coinbase"))->ToString());
shash = *shash_;
} else { } else {
txin.prevout.hash.GetHex() = in->Get(NanNew<String>("txid"))->ToString(); String::AsciiValue shash_(obj->Get(NanNew<String>("scriptSig"))->ToString());
(boost::int64_t)txin.prevout.n = in->Get(NanNew<String>("vout"))->IntegerValue(); shash = *shash_;
Local<Object> o = in->Get(NanNew<String>("scriptSig"));
txin.scriptSig.ToString() = o->Get(NanNew<String>("asm"))->ToString();
HexStr(txin.scriptSig.begin(), txin.scriptSig.end()) = o->Get(NanNew<String>("hex"))->ToString();
} }
(boost::int64_t)txin.nSequence = in->Get(NanNew<String>("sequence"))->IntegerValue(); CScript scriptSig(shash);
txin.scriptSig = scriptSig;
String::AsciiValue phash__(in->Get(NanNew<String>("txid"))->ToString());
std::string phash_ = *phash__;
if (phash_[1] != 'x') phash_ = "0x" + phash_;
uint256 phash(phash_);
txin.prevout.hash = phash;
txin.prevout.n = (boost::int64_t)in->Get(NanNew<String>("vout"))->IntegerValue();
txin.nSequence = (boost::int64_t)in->Get(NanNew<String>("sequence"))->IntegerValue();
tx.vin.push_bask(txin);
} }
Local<Array> vout = Local<Array>::Cast(entry->Get("vout")); Local<Array> vout = Local<Array>::Cast(entry->Get("vout"));
for (unsigned int vo = 0; vo < vout->Length(); vo++) { for (unsigned int vo = 0; vo < vout->Length(); vo++) {
CTxOut txout; const CTxOut txout;
Local<Object> out = vout->Get(vo); Local<Object> out = Local<Object>::Cast(vout->Get(vo));
txout.nValue = out->Get(NanNew<String>("value"))->IntegerValue();
(boost::int64_t)vo = out->Get(NanNew<String>("n"))->IntegerValue();
Local<Object> o = out->Get(NanNew<String>("scriptPubKey")); txout.nValue = (int64_t)out->Get(NanNew<String>("value"))->IntegerValue();
{
CScript scriptPubKey;
Local<Object> out = o;
int nRequired; Local<Object> spk = Local<Object>::Cast(in->Get(NanNew<String>("scriptPubKey")));
scriptPubKey.ToString() = out->Get(NanNew<String>("asm"))->ToString(); String::AsciiValue phash__(spk->Get(NanNew<String>("hex")));
if (out->Get(NanNew<String>("hex"))->IsString()) { std::string phash_ = *phash__;
HexStr(scriptPubKey.begin(), scriptPubKey.end()) = out->Get(NanNew<String>("hex"))->ToString(); if (phash_[1] != 'x') phash_ = "0x" + phash_;
} uint256 phash(phash_);
if (out->Get(NanNew<String>("type"))->IsString()) { CScriptPubKey scriptPubKey(phash);
GetTxnOutputType(type) = out->Get(NanNew<String>("type"))->ToString();
} else {
nRequired = out->Get(NanNew<String>("reqSigs"))->IntegerValue();
GetTxnOutputType(type) = out->Get(NanNew<String>("type"))->ToString();
Local<Array> a = Local<Array>::Cast(out->Get("addresses"));
for (int ai = 0; ai < a->Length(); ai++) {
CTxDestination addr;
CBitcoinAddress(addr).ToString() = a->get(ai)->ToString();
}
}
}
}
if (entry->Get(NanNew<String>("blockhash"))->IsString()) { txout.scriptPubKey = scriptPubKey;
hashBlock.GetHex() = entry->Get(NanNew<String>("blockhash"))->ToString();
CBlockIndex pindex; tx.vout.push_back(txout);
if (entry->Get("time")->IsNumber()) {
1 + chainActive.Height() - pindex->nHeight = entry->Get(NanNew<String>("confirmations"))->IntegerValue();
(boost::int64_t)pindex->nTime = entry->Get(NanNew<String>("time"))->IntegerValue();
(boost::int64_t)pindex->nTime = entry->Get(NanNew<String>("blocktime"))->IntegerValue();
} else {
0 = entry->Get(NanNew<String>("confirmations"))->IntegerValue();
}
} }
} }
#endif #endif