【问题标题】:Identify bitcoin transaction MySQL Query problems识别比特币交易 MySQL Query 问题
【发布时间】:2014-07-11 08:11:47
【问题描述】:

我有一个保存用户数据的用户表

++ id  | username | btc_recive_address++
----------------------------------------
++  1  | myuser   | 123kahpoiq31328   ++

订单表

 ++ order_id  | user_id | amount  | order_timestamp
 ------------------------------------------------------
 ++ h6765-a1s | 1       | 0.1 BTC | 2014-04-09 13:21:34 
 ------------------------------------------------------
 ++ kzg765-a1 | 1       | 0.1 BTC | 2014-04-09 17:11:23

以及从比特币 API 检索数据的收集器表(这里我用 btc_recive_address 识别发送者)

++ block_chain      | user | amount | timestamp
--------------------------------------------------------------------------------
++ 2d37e5351196...  | 1    | 0.1    | 2014-04-09 16:21:34
--------------------------------------------------------------------------------
++ 123kjhg7231k..   | 1    | 0.1    | 2014-04-08 19:33:56
--------------------------------------------------------------------------------

我尝试将事务分配给 order_id,例如从订单和收集器表生成连接视图,但是当金额和用户相同时我会遇到问题

问题

用户下了多个相同价值的订单

0,1 X 3

我从 API 取回交易数据,而不是用接收者地址识别用户

someaddress -(这里的交易有 3 个传入确认)

比我尝试构建一个 MySQL 视图作为比较

带有收集器表的订单表,例如加入用户和金额。当金额和用户相同时,我认为我没有从 order_table 中获得唯一的 transaction_id

这里是视图查询

ALTER ALGORITHM=UNDEFINED DEFINER=`my_view`@`%` SQL SECURITY DEFINER VIEW `ci_orders_in` AS (
SELECT
  `c`.`block_chain`       AS `block_chain`,
  `c`.`assigned_user`     AS `assigned_user`,
  `c`.`incoming_amount`   AS `incoming_amount`,
  `c`.`timestamp`         AS `timestamp`,
  `c`.`type`              AS `type`,
  `c`.`category`          AS `category`,
  `c`.`import_timestamp`  AS `import_timestamp`,
  `o`.`transaction_id`    AS `transaction_id`,
  `o`.`datum`             AS `datum`,
  `o`.`status`            AS `status`,
  `o`.`convert_coin`      AS `convert_coin`,
  `o`.`convert_coin_to`   AS `convert_coin_to`,
  `o`.`amount`            AS `amount`,
  `o`.`converted_amount`  AS `converted_amount`,
  `o`.`conversion_rate`   AS `conversion_rate`,
  `o`.`user`              AS `user`,
  `o`.`units_to_transfer` AS `units_to_transfer`,
  `o`.`provision`         AS `provision`
FROM (`ci_orders` `o`
   JOIN `ci_collector` `c`
     ON ((`o`.`user` = `c`.`assigned_user`)))
WHERE (`o`.`convert_coin` = `c`.`type`)
GROUP BY `o`.`converted_amount`)$$

DELIMITER ;

在这里我应该使用另一个连接,它应该给我最近的时间戳,但我不接受它

【问题讨论】:

  • 您遇到什么问题可以具体说明吗?
  • 问题是,例如,当我有来自同一用户的多个 0,1BTC 交易时,交易 ID 将无法获得应分配的。我已经在查看具有类似 transaction_id 的交易不应该发生的事情
  • 仍然不清楚您是否可以添加更多示例数据和您正在查看的所需输出?

标签: mysql api transactions bitcoin


【解决方案1】:

看看您的视图,很明显您没有向我们展示这些表中的所有列,并且您伪造了表名,因为查询在 ci_order 表中有列“user”,但在示例数据具有“user_id”列。但是,由于我在比特币 SE 网站上阅读了您的问题,并且对您正在尝试做的事情隐约熟悉,我猜您会想要一个类似于此的查询

[错误查询]

编辑: 很抱歉没有更仔细地查看时间戳。这次我实际上费心将您的数据集加载到 SQL (MS SQL 2014) 中,尽管我可能稍微重命名了这些列。这个怎么样?另外,如果您可以提供有关延迟的详细信息,那将很有帮助,例如订单时间戳是否总是在收集器时间戳之后?

select *
from ci_orders
join ci_collector
    on ci_orders.user_id = ci_collector.user_id
    and ci_orders.amount = ci_collector.amount
    and ci_collector.timestamp = (
        select top 1 timestamp
        from ci_collector
        where ci_orders.user_id = ci_collector.user_id
        and ci_orders.amount = ci_collector.amount
        and ci_orders.timestamp > ci_collector.timestamp
        order by timestamp desc
    )

【讨论】:

  • 该连接不起作用,因为 2 个时间戳之间存在延迟
  • 正如我所说,我更改了一些列名,例如使两个表中的 user_id 匹配,而不是 user 和 user_id。同样如前所述,它是在 Microsoft SQL 2014 上运行的,尽管我认为它可以在 MySQL 中运行;我认为没有任何特定于 MS SQL 的东西。它会给你什么错误?
猜你喜欢
  • 2014-01-22
  • 1970-01-01
  • 1970-01-01
  • 2021-04-15
  • 2017-03-11
  • 2016-01-09
  • 2012-05-31
  • 2012-02-02
  • 1970-01-01
相关资源
最近更新 更多