Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Front/back]: Swap history #18

Closed
Milerius opened this issue Feb 9, 2020 · 6 comments
Closed

[Front/back]: Swap history #18

Milerius opened this issue Feb 9, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request todo 🗒️

Comments

@Milerius
Copy link
Contributor

Milerius commented Feb 9, 2020

QVariantMap jsonmodel:

{
  "491df802-43c3-4c73-85ef-1c4c49315ac6": {
    "events": [
      {
        "Started": {
          "human_timestamp": "19 Janvier 2020 19h37"
        }
      },
      {
        "Finished": {
          "human_timestamp": "19 Janvier 2020 19h38"
        }
      }
    ],
    "taker_coin": "BTC",
    "maker_coin": "KMD",
    "maker_amount": "1",
    "taker_amout": "1",
    "type": "Taker",
    "my_info": {
      "my_amount": "1",
      "my_coin": "BTC",
      "other_amount": "1",
      "other_coin": "KMD",
      "started_at": 1561481967
    }
  }
}
@Milerius Milerius added enhancement New feature or request todo 🗒️ labels Feb 9, 2020
@Milerius
Copy link
Contributor Author

Milerius commented Feb 9, 2020

QVariantMap
    application::get_recent_swaps()
    {
        QVariantMap out;
        const auto& swaps = get_mm2().get_swaps();

        for (auto&& swap: swaps.swaps)
        {
            nlohmann::json j2 = {{"maker_coin", swap.maker_coin},
                                 {"taker_coin", swap.taker_coin},
                                 {"maker_amount", swap.maker_amount},
                                 {"taker_amount", swap.taker_amount},
                                 {"type", swap.type},
                                 {"events", swap.events},
                                 {"my_info", swap.my_info}};

            auto out_swap = QJsonDocument::fromJson(QString::fromStdString(j2.dump()).toUtf8());
            out.insert(QString::fromStdString(swap.uuid), QVariant(out_swap));
        }
        return out;
    }

@Milerius
Copy link
Contributor Author

Milerius commented Feb 9, 2020

For the swap history, you just have to go through the event object, depending on the current event display information in the history.

For example if I have the Finished event, it is because everything went well, and therefore the swap is finished, what will interest you in this case is the uuid, the human timestamp , the amount of the swap, if you are a taker or a maker.

@cipig
Copy link
Member

cipig commented Feb 9, 2020

Finished does not necessarily mean successfull. Here is an example:

{
   "mm_version" : "8a7fd8624",
   "success_events" : [
      "Started",
      "Negotiated",
      "TakerFeeValidated",
      "MakerPaymentSent",
      "TakerPaymentReceived",
      "TakerPaymentWaitConfirmStarted",
      "TakerPaymentValidatedAndConfirmed",
      "TakerPaymentSpent",
      "Finished"
   ],
   "maker_amount" : "2.26631977",
   "error_events" : [
      "StartFailed",
      "NegotiateFailed",
      "TakerFeeValidateFailed",
      "MakerPaymentTransactionFailed",
      "MakerPaymentDataSendFailed",
      "MakerPaymentWaitConfirmFailed",
      "TakerPaymentValidateFailed",
      "TakerPaymentWaitConfirmFailed",
      "TakerPaymentSpendFailed",
      "MakerPaymentWaitRefundStarted",
      "MakerPaymentRefunded",
      "MakerPaymentRefundFailed"
   ],
   "gui" : "mpm",
   "taker_coin" : "KMD",
   "events" : [
      {
         "timestamp" : 1581244037425,
         "event" : {
            "type" : "StartFailed",
            "data" : {
               "error" : "maker_swap:235] !check_i_have_enough_to_trade utxo:1427] Amount 2.26631977 is too low, it'll result to dust error, at least 5 is required"
            }
         }
      },
      {
         "timestamp" : 1581244037426,
         "event" : {
            "type" : "Finished"
         }
      }
   ],
   "maker_coin" : "DOGE",
   "uuid" : "7dcdefc3-d63d-4c39-99bb-b962328f69a3",
   "taker_amount" : "0.0100000000059388"
}

to check if a swap was successfull, i iterate through all events and check if any of them is of type error_events
the presence of the Finished event means that the swap is not ongoing atm.

@Milerius
Copy link
Contributor Author

Milerius commented Feb 9, 2020

@cipig Thank's for this specification, really precious 🙏

@Milerius
Copy link
Contributor Author

Milerius commented Feb 9, 2020

I hope cipig clarification will help you @naezith

In the idea if you have at least one event that is in error the final status will probably not be success, so if you have Finished and you have no error event, then I guess that means that all went well.

@Milerius
Copy link
Contributor Author

Implemented !

smk762 pushed a commit that referenced this issue Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request todo 🗒️
Projects
None yet
Development

No branches or pull requests

3 participants