当前位置: 首页>>代码示例>>C++>>正文


C++ CTransaction::GetHashForLog方法代码示例

本文整理汇总了C++中CTransaction::GetHashForLog方法的典型用法代码示例。如果您正苦于以下问题:C++ CTransaction::GetHashForLog方法的具体用法?C++ CTransaction::GetHashForLog怎么用?C++ CTransaction::GetHashForLog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CTransaction的用法示例。


在下文中一共展示了CTransaction::GetHashForLog方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: error

bool
CreateGameTransactions (CNameDB& nameDb, const GameState& gameState,
                        const StepResult& stepResult,
                        std::vector<CTransaction>& outvgametx)
{
  if (fDebug)
    printf ("Constructing game tx @%d...\n", gameState.nHeight);

  // Create resulting game transactions
  // Transaction hashes must be unique
  outvgametx.clear ();

  CTransaction txNew;
  txNew.SetGameTx ();

  // Destroy name-coins of killed players
  const PlayerSet& killedPlayers = stepResult.GetKilledPlayers ();
  const KilledByMap& killedBy = stepResult.GetKilledBy ();
  txNew.vin.reserve (killedPlayers.size ());
  BOOST_FOREACH(const PlayerID &victim, killedPlayers)
    {
      const vchType vchName = vchFromString (victim);
      CTransaction tx;
      if (!GetTxOfNameAtHeight (nameDb, vchName, gameState.nHeight, tx))
        return error ("Game engine killed a non-existing player %s",
                      victim.c_str ());

      if (fDebug)
        printf ("  killed: %s\n", victim.c_str ());

      CTxIn txin(tx.GetHash (), IndexOfNameOutput (tx));

      /* List all killers, if player was simultaneously killed by several
         other players.  If the reason was not KILLED_DESTRUCT, handle
         it also.  If multiple reasons apply, the game tx is constructed
         for the first reason according to the ordering inside of KilledByMap.
         (Which in turn is determined by the enum values for KILLED_*.)  */

      typedef KilledByMap::const_iterator Iter;
      const std::pair<Iter, Iter> iters = killedBy.equal_range (victim);
      if (iters.first == iters.second)
        return error ("No reason for killed player %s", victim.c_str ());
      const KilledByInfo::Reason reason = iters.first->second.reason;

      /* Unless we have destruct, there should be exactly one entry with
         the "first" reason.  There may be multiple entries for different
         reasons, for instance, killed by poison and staying in spawn
         area at the same time.  */
      {
        Iter it = iters.first;
        ++it;
        if (reason != KilledByInfo::KILLED_DESTRUCT && it != iters.second
            && reason == it->second.reason)
          return error ("Multiple same-reason, non-destruct killed-by"
                        " entries for %s", victim.c_str ());
      }

      switch (reason)
        {
        case KilledByInfo::KILLED_DESTRUCT:
          txin.scriptSig << vchName << GAMEOP_KILLED_BY;
          for (Iter it = iters.first; it != iters.second; ++it)
            {
              if (it->second.reason != KilledByInfo::KILLED_DESTRUCT)
                {
                  assert (it != iters.first);
                  break;
                }
              txin.scriptSig << vchFromString (it->second.killer.ToString ());
            }
          break;

        case KilledByInfo::KILLED_SPAWN:
          txin.scriptSig << vchName << GAMEOP_KILLED_BY;
          break;

        case KilledByInfo::KILLED_POISON:
          txin.scriptSig << vchName << GAMEOP_KILLED_POISON;
          break;

        default:
          assert (false);
        }

      txNew.vin.push_back (txin);
    }
  if (!txNew.IsNull ())
    {
      outvgametx.push_back (txNew);
      if (fDebug)
        printf ("Game tx for killed players: %s\n", txNew.GetHashForLog ());
    }

  /* Pay bounties to the players who collected them.  The transaction
     inputs are just "dummy" containing informational messages.  */
  txNew.SetNull ();
  txNew.SetGameTx ();
  txNew.vin.reserve (stepResult.bounties.size ());
  txNew.vout.reserve (stepResult.bounties.size ());

//.........这里部分代码省略.........
开发者ID:BGBHUC,项目名称:huntercoin,代码行数:101,代码来源:gametx.cpp


注:本文中的CTransaction::GetHashForLog方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。