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

all transactions for account endpoint #725

Closed
thepiwo opened this issue Jun 16, 2022 · 22 comments
Closed

all transactions for account endpoint #725

thepiwo opened this issue Jun 16, 2022 · 22 comments
Assignees
Labels

Comments

@thepiwo
Copy link
Collaborator

thepiwo commented Jun 16, 2022

make an endpoiint that returns all tranactions for one account

  • aex 9
  • aex 141
  • internal transfers (name fee, ...)
  • token migration tokens
  • function calls (Chain.spend)
  • native transactions

with both plain tx that has that information, as well as

@thepiwo
Copy link
Collaborator Author

thepiwo commented Jun 16, 2022

(cc @CedrikNikita )

@thepiwo
Copy link
Collaborator Author

thepiwo commented Jun 22, 2022

name proposal from @sborrazas activity with different payload fields for different activity types. Paginated, never nested.

@sborrazas
Copy link
Contributor

@thepiwo
Copy link
Collaborator Author

thepiwo commented Jun 30, 2022

Goal

Expose all "activity" of one account, the consumer of the api wants to know everything that happened to the account, so
we should expose all data we know of.

Basic Design

  • always expose three field
    • enum for what type the "activity" is
    • original transaction it has been included (no nested aggregated data, maybe null if not exposed via transaction)
    • additional information depending on the "activity" type as we have it stored
  • filters available
    • by account (eventually mandatory)
    • by enum "activity" (multiple if possible)
    • by height, txi and other scopes we usually provide
[
  {
    "transaction": {
      ...
    },
    "type": "native_transaction",
    "additional_data": null
  },
  {
    "transaction": {
      ...
    },
    "type": "aex9_transfer",
    "additional_data": {
      "amount": 10,
      "contract_id": "ct_UAKGhMFJThpxgyFQi4fXztvT2fZRcMgZxjqrT9ehwsZT1yUe1",
      "recipient": "ak_y87WkN4C4QevzjTuEYHg6XLqiWx3rjfYDFLBmZiqiro5mkRag",
      "sender": "ak_45tM79u5EgCmsorADwuhf4PXkzEEBSHzXRZwjfBe5ww48XX63",
      ...
    }
  }
]

Examples

SpendTx (any native)

{
  "transaction": {
    "block_hash": "mh_EgvpfzAWAxes5xoFut3ADQBk9G9FpwdSFGnfXiV3anErouSC5",
    "block_height": 621066,
    "hash": "th_zDTyHWyVxMvmZmPhQZgnpdtHsbRMR6aLj7aADBKJqekkstmzG",
    "micro_index": 0,
    "micro_time": 1656616116824,
    "signatures": [
      "sg_P6EM1qzVx7HdP2dHR1bYU3LRrXjiAt6gvSKkg8bc4gLJRWf8Pme6akqFadytNLgpxFUKgDqxvpoCYHiDdSdeQDUieLAGs"
    ],
    "tx": {
      "amount": 455158420000000000000,
      "fee": 20000000000000,
      "nonce": 283,
      "payload": "ba_Xfbg4g==",
      "recipient_id": "ak_jgiBUko9fTwg5HQ8nHFoPbjR22TBcg9LK85qsv1mTkcjdszFa",
      "sender_id": "ak_NcCfoP4M99vDfDSj6AKE4d3t7DBYE7UfB5rUJYggdPa23eWUp",
      "type": "SpendTx",
      "version": 1
    },
    "tx_index": 32696747
  },
  "type": "native_transaction",
  "additional_data": null
}

AEX-9 Transfer

{
  "transaction": {
    "block_hash": "mh_2YhPW2gJSxJSRhiuLNR3MaHrAXew87FezsPh935KWW4Cmxi7dT",
    "block_height": 423470,
    "hash": "th_pGTAgCsBAQ8wzPRoi5mBL7koJypNpjgeYnFgWbwLcvouBgS3P",
    "micro_index": 29,
    "micro_time": 1619772609406,
    "signatures": [
      "sg_CicUTeiDLBCch8ANHg6K6pn7GVgNnnKWxkX7KpGZo3sMV8yS7zsNnRtypnM4VTpQnrNASStQqnX2KtXc8fd1cXKbRMmXS"
    ],
    "tx": {
      "abi_version": 3,
      "amount": 0,
      "arguments": [
        {
          "type": "int",
          "value": 2858
        },
        {
          "type": "contract",
          "value": "ct_2bCbmU7vtsysL4JiUdUZjJJ98LLbJWG1fRtVApBvqSFEM59D6W"
        },
        {
          "type": "int",
          "value": 200000000000000000
        }
      ],
      "call_data": "cb_KxHLCaNVO2+CCuqfAqDRWfKB3b5gQ3QKTfjbMKv96kYvxVf2F3UwAuh4cm8OzG+IAsaK8LsT/8CKC6KO",
      "caller_id": "ak_y87WkN4C4QevzjTuEYHg6XLqiWx3rjfYDFLBmZiqiro5mkRag",
      "contract_id": "ct_2ZEoCKcqXkbz2uahRrsWeaPooZs9SdCv6pmC4kc55rD4MhqYSu",
      "fee": 183040000000000,
      "function": "retip_token",
      "gas": 1579000,
      "gas_price": 1000000000,
      "gas_used": 14397,
      "log": [
        {
          "address": "ct_2ZEoCKcqXkbz2uahRrsWeaPooZs9SdCv6pmC4kc55rD4MhqYSu",
          "data": "cb_aHR0cHM6Ly9naXRodWIuY29tL3RoZXBpd28/dGFiPXByb2plY3Rz5wjuPw==",
          "topics": [
            "69233040432260092823535072650704575529616496835825451258994902650498116489956",
            "57639713195292369493552360805284271936076756489947923784567159882221348109905",
            "200000000000000000",
            "94692308466469327368914015067879324067711091014055784310570568810048676368076"
          ]
        },
        {
          "address": "ct_2bCbmU7vtsysL4JiUdUZjJJ98LLbJWG1fRtVApBvqSFEM59D6W",
          "data": "cb_Xfbg4g==",
          "topics": [
            "15485047184846566156736396069994907050875216973023180189891727495730853981167",
            "57639713195292369493552360805284271936076756489947923784567159882221348109905",
            "92677149171721727644907713804262804720581801637012226274906210727390161108525",
            "200000000000000000"
          ]
        },
        {
          "address": "ct_2bCbmU7vtsysL4JiUdUZjJJ98LLbJWG1fRtVApBvqSFEM59D6W",
          "data": "cb_Xfbg4g==",
          "topics": [
            "6675387653529534352993899574763440621350730065146058041830673378811230846814",
            "57639713195292369493552360805284271936076756489947923784567159882221348109905",
            "92677149171721727644907713804262804720581801637012226274906210727390161108525",
            "0"
          ]
        }
      ],
      "nonce": 1766,
      "result": "ok",
      "return": {
        "type": "int",
        "value": 216
      },
      "return_type": "ok",
      "type": "ContractCallTx",
      "version": 1
    },
    "tx_index": 20904005
  },
  "type": "aex_9_transfer",
  "additional_data": {
    "amount": 2000000000000000000,
    "block_height": 570863,
    "call_txi": 27125236,
    "contract_id": "ct_2eyXvDw3V3WSbcCpSiWcsCYHShBmEJEkU8PpUg7ymDLfZ4cSy4",
    "log_idx": 5,
    "micro_index": 0,
    "micro_time": 1646658412647,
    "recipient": "ak_Dh8X2kkZGiDVnG3LhgvRbWnfj9hxo9RUFFcdA6wFvHsNfTGpV",
    "sender": "ak_y87WkN4C4QevzjTuEYHg6XLqiWx3rjfYDFLBmZiqiro5mkRag",
    "tx_hash": "th_29pmGLe7Qp5vGaXUvASkSdrQ4LuQjg8e11QTzQqGxu7y81iydN"
  }
}

Dev Reward Internal Transfer

{
  "transaction": null,
  "type": "dev_reward_internal_transfer",
  "additional_data": {
    "account_id": "ak_2KAcA2Pp1nrR8Wkt3FtCkReGzAi8vJ9Snxa4PcmrthVx8AhPe8",
    "amount": 9374108171600000000,
    "height": 621083,
    "kind": "reward_dev",
    "ref_txi": null
  }
}

Fee Spend Name Internal Transfer

{
  "transaction": {
    "block_hash": "mh_B9uuhUDYtMgUtkgN1a9TVagTytE4ZAtKBm6JW4XW9N4LndV3d",
    "block_height": 620836,
    "hash": "th_PGDRcCRHjbssJAHqjh4ADRhzgELAF3jFcZeCMWZdkDLeGmfUu",
    "micro_index": 4,
    "micro_time": 1656572103392,
    "signatures": [
      "sg_LcDTJSn3CdrAGuqUzsZVqxzx9baNbES456ExGH2ZQxVGeY5wGMyGwoH3oTS4y44GUZB29rnzPViXjfTF1D1iLxybYihAn"
    ],
    "tx": {
      "account_id": "ak_nWpUc3yymNLY5f2qD2dU1K1dx1ZcsrSP3ifNNsA4b363CqKDx",
      "fee": 16480000000000,
      "name": "zx.chain",
      "name_fee": 352457800000000000000,
      "name_id": "nm_HTS4fu1A29yMMweSG7yifBByBBZiXj82UQjHbWBPKuXkUFcyH",
      "name_salt": 1745513846490943,
      "nonce": 2,
      "type": "NameClaimTx",
      "version": 2
    },
    "tx_index": 32694596
  },
  "type": "fee_spend_name_internal_transfer",
  "additional_data": {
    "account_id": "ak_nWpUc3yymNLY5f2qD2dU1K1dx1ZcsrSP3ifNNsA4b363CqKDx",
    "amount": 352457800000000000000,
    "height": 620836,
    "kind": "fee_spend_name",
    "ref_txi": 32694596
  }
}

Chain.spend Function Call

{
  "transaction": {
    "block_hash": "mh_2PNjxt4DszdKGMmYLPbV63cbGrZLkm1odoge4z1gQid1d9zWQC",
    "block_height": 618669,
    "hash": "th_28a8fwiYnSonAJxBP2KAm94SNDAkag3h1XvJj8yuDBZHvaKN8J",
    "micro_index": 5,
    "micro_time": 1656172299548,
    "signatures": [
      "sg_GosVdwVhZ4Av2h4PTpLkQJun49ZSAZHvu9KzioG8zwcYaBNiqnwe2f3geZRXdcDjB5Q2CWwi8v8EQjM4b9MnCpzw6BpJ3"
    ],
    "tx": {
      "abi_version": 3,
      "amount": 371660000000000000000,
      "arguments": [
        {
          "type": "contract",
          "value": "ct_KeTvHnhU85vuuQMMZocaiYkPL9tkoavDRT3Jsy47LK2YqLHYb"
        },
        {
          "type": "address",
          "value": "ak_DPS1pLckyQ8CqhRymcKh9q9XE52LjTU5Rwj2mH48Eb4Bx67vK"
        }
      ],
      "call_data": "cb_KxEV1igBK58CoCpWfsefy3sCXPsFoNwnsjiGX+2lbjncVIK2cClM26tcnwCgHCAoyxtaCJbLJyXYtXkCw+eQsfSWRuxrLO2k5clPpw0TjobM",
      "caller_id": "ak_QKEU2UZagBLMjGzTXG6fSHRW5BYL6ygoU6PXde8oFZEazxuRd",
      "contract_id": "ct_2meHkLcAoZPrQj7P5WjFyJJRLJqRtv43z1QEbpcS1gHs9W8Q3g",
      "fee": 183600000000000,
      "function": "buy",
      "gas": 1579000,
      "gas_price": 1000000000,
      "gas_used": 248068,
      "log": [
        {
          "address": "ct_KeTvHnhU85vuuQMMZocaiYkPL9tkoavDRT3Jsy47LK2YqLHYb",
          "data": "cb_Xfbg4g==",
          "topics": [
            "15485047184846566156736396069994907050875216973023180189891727495730853981167",
            "105417517163555785945723224801218696668870882222503184278035313886450621180253",
            "78358310802666329243274638441415362276768191830085298940556170962395967841219",
            "557490000000000000000"
          ]
        },
        {
          "address": "ct_KeTvHnhU85vuuQMMZocaiYkPL9tkoavDRT3Jsy47LK2YqLHYb",
          "data": "cb_Xfbg4g==",
          "topics": [
            "15485047184846566156736396069994907050875216973023180189891727495730853981167",
            "105417517163555785945723224801218696668870882222503184278035313886450621180253",
            "23944573204997539868635097841906515400749890475032264081717075850491652064526",
            "36608510000000000000000"
          ]
        }
      ],
      "nonce": 122,
      "result": "ok",
      "return": {
        "type": "tuple",
        "value": [
          {
            "type": "address",
            "value": "ak_DPS1pLckyQ8CqhRymcKh9q9XE52LjTU5Rwj2mH48Eb4Bx67vK"
          },
          {
            "type": "string",
            "value": "WTT"
          },
          {
            "type": "contract",
            "value": "ct_KeTvHnhU85vuuQMMZocaiYkPL9tkoavDRT3Jsy47LK2YqLHYb"
          },
          {
            "type": "int",
            "value": 1653821085955
          },
          {
            "type": "int",
            "value": 605929
          },
          {
            "type": "int",
            "value": 3.7166e+22
          },
          {
            "type": "int",
            "value": 371660000000000000000
          }
        ]
      },
      "return_type": "ok",
      "type": "ContractCallTx",
      "version": 1
    },
    "tx_index": 32660685
  },
  "type": "chain_spend_function_call",
  "additional_data": {
    "block_hash": "mh_2PNjxt4DszdKGMmYLPbV63cbGrZLkm1odoge4z1gQid1d9zWQC",
    "call_tx_hash": "th_28a8fwiYnSonAJxBP2KAm94SNDAkag3h1XvJj8yuDBZHvaKN8J",
    "call_txi": 32660685,
    "contract_id": "ct_2meHkLcAoZPrQj7P5WjFyJJRLJqRtv43z1QEbpcS1gHs9W8Q3g",
    "contract_txi": 21130617,
    "function": "Chain.spend",
    "height": 618669,
    "internal_tx": {
      "amount": 366085100000000000000,
      "fee": 0,
      "nonce": 0,
      "payload": "ba_Q2hhaW4uc3BlbmRFa4Tl",
      "recipient_id": "ak_DPS1pLckyQ8CqhRymcKh9q9XE52LjTU5Rwj2mH48Eb4Bx67vK",
      "sender_id": "ak_2meHkLcAoZPrQj7P5WjFyJJRLJqRtv43z1QEbpcS1gHs9W8Q3g",
      "type": "SpendTx",
      "version": 1
    },
    "local_idx": 1,
    "micro_index": 5
  }
}

Discussion

  • How do we want to deal with meta transactions and their nexting, e.g. how should we expose the inner transactions
    of paying_for and ga_meta while filtering for the inner transactions account?

One idea would be to list the inner transaction that's relevant for the account as additional_data with a
different type to indicate special handling.

  • How can we index what information to find for which account?

I feel like we have account filter for most of this data already, maybe we need some additional shared index, plus maybe indexes for information like the function calls where this filter doesn't exist yet.

@sborrazas
Copy link
Contributor

  • I think being able to filter activities by account and scope it to a range of generations would be the most useful feature, because if we want to have ALL activities filtered by range then the index that we would need would be an additional (very big) index, and I'm not sure how useful that would be (thousand if not more activities per generation). IMO, for the most part, I think this feature is covered by simply listing transactions

  • For the paying_for and ga_meta and any other transaction nesting we should probably include it in the transaction meta-info (both in this new endpoint and on the /txs endpoint as well):

{
   "tx": {
      "type": "PayingForTx",
      "inner_tx": {
        "type": "SpendTx",
        ...
    }
}

In this case both tx and inner_tx would have the same structure ("type", "gas", "vm_version", etc)

Additionally, we should add the height, mbi, txi and local_index (better name?) to the activity response structure. (height, mbi, local_index) would then be the unique index to be used to identify the activity (the index would end up being (address, height, mbi, local_index)):

{
  "activity_type": "mb_mined" | "kb_mined" | "contract_called" | "contract_call_event_created" | "aex9_transferred" | ...,
  "activity_payload": {
    "mining_fee": 1,
    "mb_hash": "mb_..."
  },
  "height": 123,
  "mbi": -1 (key block) | 10,
  "local_index": 0,
  "tx": null | {"type": ...}
}

It would be nice to be able to list all activity types (type and payload) that we want, including transactions obtained via "transaction events" which occur when executing a contract call, mining events and all the events that aexn function calls trigger

@thepiwo
Copy link
Collaborator Author

thepiwo commented Jul 1, 2022

should also include contract call log event account occurrence

@sborrazas
Copy link
Contributor

As per our meeting discussion, we should probably deal with activities that are related to a transaction include the transaction inside the activity_payload. E.g.

{
  "activity_type": "key_block_mined",
  "height": 1,
  "mbi": -1,
  "activity_index": 0,
  "activity_payload": {
    "kb_hash": "...",
    "mining_fee": "...",
    # notice no "tx" key in this object
  }
}

{
  "activity_type": "payment_sent",
  "height": 1,
  "mbi": 10,
  "activity_index": 20,
  "activity_payload": {
    "amount": 1,
    "sender_id": "...",
    "recipient_id": "...",
    "tx": { "type": "SpendTx", "hash": "...", "sender_id": "...", "recipient_id": "..." }
  }
}

@CedrikNikita
Copy link

CedrikNikita commented Jul 7, 2022

For the wallet it is also important within such endpoint to have a aex9 related transactions, where the account (address) is also a receiver, not only sender.

For example:

  • /aex9/transfers/to/ this endpoint is not presented in the /txs/backward

@thepiwo
Copy link
Collaborator Author

thepiwo commented Aug 1, 2022

as previously discussed in #314 this should probably also be able to filter for contracts and all their information

@thepiwo
Copy link
Collaborator Author

thepiwo commented Oct 20, 2022

@sborrazas could you maybe summarise with a checklist on what is left to do here? do we want to make another issue for activities per contract + per block or track this in here as well?

@thepiwo thepiwo added this to the 2022-10-21 Planning milestone Oct 20, 2022
@sborrazas
Copy link
Contributor

@thepiwo I can't think of any other activity type that we're missing. You can already scope the activities by generations and activities per contract would only be /accounts/{contract_id}/activities.

If you can think of any other activity type that we're missing we should add it, otherwise, we can probably close this issue

@marc0olo
Copy link

is there a complete readable list I can quickly check?

I just thought about AENS name perspective. there are also historical activities of a name which we currently discussed in a explorer meeting.

we'd want to show the complete history of an AENS name, including implicit expiration / deactivation

@marc0olo
Copy link

ok sorry, this is about accounts 🤦‍♂️

mhh, can we actually already get what I was talking about for an AENS name?

but from account perspective this is also sth. to consider. somebody might transfer a name to me. I'd want to see that in the activity history

@thepiwo
Copy link
Collaborator Author

thepiwo commented Oct 20, 2022

@marc0olo yes I would expect this to be possible with activities, @sborrazas is it?

@sborrazas
Copy link
Contributor

Expiration of a name/oracle is not an activity on it's own, but we can definitely create one.

Deactivation is not an activity directly, but since deactivation is caused by a name revoke transaction it is part of the activities indirectly

@thepiwo
Copy link
Collaborator Author

thepiwo commented Oct 20, 2022

Sorry, I agree expiration is not an account activity. But I was talking about name transfer receiver.

@thepiwo
Copy link
Collaborator Author

thepiwo commented Oct 20, 2022

cool, thanks! 😍

@thepiwo
Copy link
Collaborator Author

thepiwo commented Oct 25, 2022

@marc0olo @thepiwo let us check if everything is included here that we want to filter

@jyeshe
Copy link
Member

jyeshe commented Oct 25, 2022

@thepiwo as you've asked, aexn events would be possible to be indexed on activities as well. Other non-standard event wouldn't because an integer event param comes also as a 256-bit binary from the Node to the Mdw on the call logs.

@thepiwo
Copy link
Collaborator Author

thepiwo commented Feb 28, 2023

@sborrazas maybe this can be marked as done or is there anything obv. remaining?

@sborrazas
Copy link
Contributor

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants