omgnetwork/elixir-omg

`transaction.create` doesn't deduct fee from `outputs`

Closed this issue · 5 comments

Example response:

{
  "data": {
    "result": "complete",
    "transactions": [
      {
        "fee": {
          "amount": 1,
          "currency": "0x0000000000000000000000000000000000000000"
        },
        "inputs": [
          {
            "amount": 49910000000000000,
            "blknum": 138000,
            "creating_txhash": "0xf9b02554e85ed7ed291c0a7657519d38de7ec2660db1e7e5bb0b8f0b435c0fc4",
            "currency": "0x0000000000000000000000000000000000000000",
            "inserted_at": "2020-10-29T14:20:53Z",
            "oindex": 1,
            "otype": 1,
            "owner": "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92",
            "spending_txhash": null,
            "txindex": 0,
            "updated_at": "2020-10-29T14:20:53Z",
            "utxo_pos": 138000000000001
          },
          {
            "amount": 3000,
            "blknum": 142000,
            "creating_txhash": "0x8fe5f64976fdca50c15bd6d6a1b9aa473227b5d5650dc2136a8f5fceb5d0b75a",
            "currency": "0xd5b83b1fdbc00bfe3679a60b2cb6252418df0d99",
            "inserted_at": "2020-10-29T14:58:36Z",
            "oindex": 0,
            "otype": 1,
            "owner": "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92",
            "spending_txhash": null,
            "txindex": 0,
            "updated_at": "2020-10-29T14:58:36Z",
            "utxo_pos": 142000000000000
          }
        ],
        "metadata": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "outputs": [
          {
            "amount": 700,
            "currency": "0xd5b83b1fdbc00bfe3679a60b2cb6252418df0d99",
            "owner": "0xbdba40131ec2d16f067cc242644ea69e8afd0d4a"
          },
          {
            "amount": 49910000000000000,
            "currency": "0x0000000000000000000000000000000000000000",
            "owner": "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92"
          },
          {
            "amount": 2300,
            "currency": "0xd5b83b1fdbc00bfe3679a60b2cb6252418df0d99",
            "owner": "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92"
          }
        ],
        "sign_hash": "0x6f8a85fee13ab63fdb319537e3ff8b068875b85d3f2b01f5e92f5e8b729f3656",
        "txbytes": "0xf8fe01f842a000000000000000000000000000000000000000000000000000007d82a0faa001a000000000000000000000000000000000000000000000000000008125f38ee000f895ef01ed94bdba40131ec2d16f067cc242644ea69e8afd0d4a94d5b83b1fdbc00bfe3679a60b2cb6252418df0d998202bcf401f29431bc9ea3093d5a4faeff8fdf24499cea3f7c1f9294000000000000000000000000000000000000000087b150e16cbd5fffef01ed9431bc9ea3093d5a4faeff8fdf24499cea3f7c1f9294d5b83b1fdbc00bfe3679a60b2cb6252418df0d998208fc80a00000000000000000000000000000000000000000000000000000000000000000",
        "typed_data": {
          "domain": {
            "name": "OMG Network",
            "salt": "0xfad5c7f626d80f9256ef01929f3beb96e058b8b4b0e3fe52d84f054c0e2a7a83",
            "verifyingContract": "0xb43f53394d86deab35bc2d8356d6522ced6429b5",
            "version": "1"
          },
          "message": {
            "input0": {
              "blknum": 138000,
              "oindex": 1,
              "txindex": 0
            },
            "input1": {
              "blknum": 142000,
              "oindex": 0,
              "txindex": 0
            },
            "input2": {
              "blknum": 0,
              "oindex": 0,
              "txindex": 0
            },
            "input3": {
              "blknum": 0,
              "oindex": 0,
              "txindex": 0
            },
            "metadata": "0x0000000000000000000000000000000000000000000000000000000000000000",
            "output0": {
              "amount": 700,
              "currency": "0xd5b83b1fdbc00bfe3679a60b2cb6252418df0d99",
              "owner": "0xbdba40131ec2d16f067cc242644ea69e8afd0d4a"
            },
            "output1": {
              "amount": 49910000000000000,
              "currency": "0x0000000000000000000000000000000000000000",
              "owner": "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92"
            },
            "output2": {
              "amount": 2300,
              "currency": "0xd5b83b1fdbc00bfe3679a60b2cb6252418df0d99",
              "owner": "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92"
            },
            "output3": {
              "amount": 0,
              "currency": "0x0000000000000000000000000000000000000000",
              "owner": "0x0000000000000000000000000000000000000000"
            }
          },
          "primaryType": "Transaction",
          "types": {
            "EIP712Domain": [
              {
                "name": "name",
                "type": "string"
              },
              {
                "name": "version",
                "type": "string"
              },
              {
                "name": "verifyingContract",
                "type": "address"
              },
              {
                "name": "salt",
                "type": "bytes32"
              }
            ],
            "Input": [
              {
                "name": "blknum",
                "type": "uint256"
              },
              {
                "name": "txindex",
                "type": "uint256"
              },
              {
                "name": "oindex",
                "type": "uint256"
              }
            ],
            "Output": [
              {
                "name": "outputType",
                "type": "uint256"
              },
              {
                "name": "outputGuard",
                "type": "bytes20"
              },
              {
                "name": "currency",
                "type": "address"
              },
              {
                "name": "amount",
                "type": "uint256"
              }
            ],
            "Transaction": [
              {
                "name": "txType",
                "type": "uint256"
              },
              {
                "name": "input0",
                "type": "Input"
              },
              {
                "name": "input1",
                "type": "Input"
              },
              {
                "name": "input2",
                "type": "Input"
              },
              {
                "name": "input3",
                "type": "Input"
              },
              {
                "name": "output0",
                "type": "Output"
              },
              {
                "name": "output1",
                "type": "Output"
              },
              {
                "name": "output2",
                "type": "Output"
              },
              {
                "name": "output3",
                "type": "Output"
              },
              {
                "name": "txData",
                "type": "uint256"
              },
              {
                "name": "metadata",
                "type": "bytes32"
              }
            ]
          }
        }
      }
    ]
  },
  "service_name": "watcher_info",
  "success": true,
  "version": "1.0.5+54305bb"
}

Alright, so if you look at this function that builds a transaction’s outputs, you see that the fee is passed in along with the payments for the derivation of the “change” amount. So the “change” output takes into account the fee. If you look at the test suite, the deduction of the fees is also clearly covered in multiple tests (see : here. – it’s not explicit but you can conclude with some simple arithmetic) (edited)

Call to https://watcher-info.rinkeby.v1.omg.network/transaction.create with OMG fee:

Request Parameters:

{
  "fee" : {"currency": "0x0000000000000000000000000000000000000000"},
  "owner":  "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92",
  "payments": [
    {
      "amount": 1,
      "currency": "0x0000000000000000000000000000000000000000",
      "owner": "0xc139e1d7358e4faf76f0fcf792255016af5dc742"
    }
  ]	
}

Response:

...
 "inputs": [
          {
            "amount": 49910000000000000,
            "blknum": 138000,
            "creating_txhash": "0xf9b02554e85ed7ed291c0a7657519d38de7ec2660db1e7e5bb0b8f0b435c0fc4",
            "currency": "0x0000000000000000000000000000000000000000",
            "inserted_at": "2020-10-29T14:20:53Z",
            "oindex": 1,
            "otype": 1,
            "owner": "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92",
            "spending_txhash": null,
            "txindex": 0,
            "updated_at": "2020-10-29T14:20:53Z",
            "utxo_pos": 138000000000001
          }
        ],
        "metadata": null,
        "outputs": [
          {
            "amount": 1,
            "currency": "0x0000000000000000000000000000000000000000",
            "owner": "0xc139e1d7358e4faf76f0fcf792255016af5dc742"
          },
          {
            "amount": 49909999999999998,
            "currency": "0x0000000000000000000000000000000000000000",
            "owner": "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92"
          }
        ]
...

The fee is clearly being deducted in the change output.

Above call was made with the same address as the inputs owner in the issue: "0x31bc9ea3093d5a4faeff8fdf24499cea3f7c1f92"

closing as this is indeed not a bug in the watcher but an implementation detail in the clients environment. (big number rounding)