src/zmq/zmqgames.cpp
/**
 * Converts a transaction to the corresponding JSON data that is returned
 * for it in the Xaya game interface.  The returned map contains the data
 * for each of the games that may be referenced (and are tracked).  If the
 * transaction is not a name operation, then the empty map is returned.
 */
Converts a transaction to the corresponding JSON data that is returned
for it in the Xaya game interface.  The returned map contains the data
for each of the games that may be referenced (and are tracked).  If the
transaction is not a name operation, then the empty map is returned.
Converts a transaction to the corresponding JSON data that is returned for it in the Xaya game interface . The returned map contains the data for each of the games that may be referenced ( and are tracked ) . If the transaction is not a name operation then the empty map is returned .
std::map<std::string, UniValue>
JsonDataForMove (const CTransaction& tx)
{
  CNameScript nameOp;
  for (const auto& out : tx.vout)
    {
      nameOp = CNameScript (out.scriptPubKey);
      if (nameOp.isNameOp ())
        break;
    }
  if (!nameOp.isNameOp () || !nameOp.isAnyUpdate ())
    return {};
  const std::string name = EncodeName (nameOp.getOpName (), NameEncoding::UTF8);
  if (name.substr (0, 2) != "p/")
    return {};
  const std::string valueStr = EncodeName (nameOp.getOpValue (),
                                           NameEncoding::UTF8);
  UniValue value;
  if (!value.read (valueStr) || !value.isObject ())
    {
      LogPrintf ("%s: invalid value ignored\n", __func__);
      return {};
    }
  if (!value.exists ("g"))
    return {};
  const UniValue& g = value["g"];
  if (!g.isObject () || g.empty ())
    return {};
  UniValue tmpl(UniValue::VOBJ);
  tmpl.pushKV ("txid", tx.GetHash ().GetHex ());
  tmpl.pushKV ("name", name.substr (2));
  std::map<std::string, CAmount> outAmounts;
  for (const auto& out : tx.vout)
    {
      const CNameScript nameOp(out.scriptPubKey);
      if (nameOp.isNameOp ())
        continue;
      CTxDestination dest;
      if (!ExtractDestination (out.scriptPubKey, dest))
        continue;
      const std::string addr = EncodeDestination (dest);
      outAmounts[addr] += out.nValue;
    }
  UniValue out(UniValue::VOBJ);
  for (const auto& entry : outAmounts)
    out.pushKV (entry.first, ValueFromAmount (entry.second));
  tmpl.pushKV ("out", out);
  std::map<std::string, UniValue> result;
  for (const auto& game : g.getKeys ())
    {
      UniValue obj = tmpl;
      obj.pushKV ("move", g[game]);
      result[game] = obj;
    }
  return result;
}
std :: map < std :: string , UniValue > JsonDataForMove ( const CTransaction & tx ) { CNameScript nameOp ; for ( const auto & out : tx . vout ) { nameOp = CNameScript ( out . scriptPubKey ) ; if ( nameOp . isNameOp ( ) ) break ; } if ( ! nameOp . isNameOp ( ) || ! nameOp . isAnyUpdate ( ) ) return { } ; const std :: string name = EncodeName ( nameOp . getOpName ( ) , NameEncoding :: UTF8 ) ; if ( name . substr ( 0 , 2 ) != " " ) return { } ; const std :: string valueStr = EncodeName ( nameOp . getOpValue ( ) , NameEncoding :: UTF8 ) ; UniValue value ; if ( ! value . read ( valueStr ) || ! value . isObject ( ) ) { LogPrintf ( " \n " , __func__ ) ; return { } ; } if ( ! value . exists ( " " ) ) return { } ; const UniValue & g = value [ " " ] ; if ( ! g . isObject ( ) || g . empty ( ) ) return { } ; UniValue tmpl ( UniValue :: VOBJ ) ; tmpl . pushKV ( " " , tx . GetHash ( ) . GetHex ( ) ) ; tmpl . pushKV ( " " , name . substr ( 2 ) ) ; std :: map < std :: string , CAmount > outAmounts ; for ( const auto & out : tx . vout ) { const CNameScript nameOp ( out . scriptPubKey ) ; if ( nameOp . isNameOp ( ) ) continue ; CTxDestination dest ; if ( ! ExtractDestination ( out . scriptPubKey , dest ) ) continue ; const std :: string addr = EncodeDestination ( dest ) ; outAmounts [ addr ] += out . nValue ; } UniValue out ( UniValue :: VOBJ ) ; for ( const auto & entry : outAmounts ) out . pushKV ( entry . first , ValueFromAmount ( entry . second ) ) ; tmpl . pushKV ( " " , out ) ; std :: map < std :: string , UniValue > result ; for ( const auto & game : g . getKeys ( ) ) { UniValue obj = tmpl ; obj . pushKV ( " " , g [ game ] ) ; result [ game ] = obj ; } return result ; }
Converts a transaction to the corresponding JSON data that is returned
 for it in the Xaya game interface.
Converts a transaction to the corresponding JSON data that is returned for it in the Xaya game interface .
/* Determine if this is a name update at all; if it isn't, then there
     is nothing to do for this transaction.  */ /* Only consider updates to p/ names.  */ /* See if there are actually games mentioned in the update's value.  */ /* This shouldn't actually happen, as the consensus rules check for
         these conditions for name updates.  But if it does happen, we just
         ignore it for here.  */ /* Prepare a template object that is the same for all games.  */ /* Fill the per-game moves into the template.  */