nem catapult secret lock/proof tx 有効期限と複数回送信

これの続き

https://qiita.com/planethouki/items/3d6c743f58692adf5814


# secret lockトランザクションは、期限が切れたらロックしたモザイクが返却されるか

答え：返却される

#### 初期状態

|  | Public| Private |
|:--:|:------:|:-------:|
| Alice | 409089866.00019 nem:xem <br /> 100 foo:bar | 1 nem:xem |
| Bob   | 409090161.99981 nem:xem <br /> 1 foo:bar | 818181817 nem:xem |

```
# node secretlock_disp.js
[1528010648244] Bob(Private) have 818181817 nem:xem
[1528010648244] Alice(Private) have 1 nem:xem
[1528010648244] Alice(Public) have 409089866.00019 nem:xem
[1528010648244] Alice(Public) have 100 foo:bar
[1528010648244] Bob(Public) have 409090161.99981 nem:xem
[1528010648244] Bob(Public) have 1 foo:bar
```

#### Secret Lockトランザクション送信

```
# node secretlock1.js
x    (proof)     : 395d00ab4a2fdd0b5813
H(x) (secret)    : 6CB8E25CB8C845AF67C59643A55721E27E7279AAE9B115B7DD5D14D5D1BDF9523B77875964F9CCDD751A3C18CBE31DA284E2ACCE07ABA47E1142203026E5DD81
tx1Signed.hash   : 32A5B80A3F2C22962A3A64AF3A57BEA82B8C30C81DFD4C3A537B1421298FDB50
tx1Signed.signer : 5D9513282B65A12A1B68DCB67DB64245721F7AE7822BE441FE813173803C512C
TransactionAnnounceResponse {
  message: 'packet 9 was pushed to the network via /transaction' }
```

Durationは60ブロック。このネットワークは、1ブロック15秒なので、15分間。

```javascript
{
  "meta": {
    "height": [
      43186,
      0
    ],
    "hash": "32A5B80A3F2C22962A3A64AF3A57BEA82B8C30C81DFD4C3A537B1421298FDB50",
    "merkleComponentHash": "32A5B80A3F2C22962A3A64AF3A57BEA82B8C30C81DFD4C3A537B1421298FDB50",
    "index": 0,
    "id": "5B139A2E80FDB3000135C2E4"
  },
  "transaction": {
    "signature": "0E422176C8939F815655223D12A0D72A9FC6D6D4A976BE4EDB803628143AF16535A785A0F426AFA43C197A8BBB338FBD1EE564C9FFCA91D88842031DF73B210B",
    "signer": "5D9513282B65A12A1B68DCB67DB64245721F7AE7822BE441FE813173803C512C",
    "version": 36867,
    "type": 16972,
    "fee": [
      0,
      0
    ],
    "deadline": [
      4124551229,
      15
    ],
    "duration": "60",
    "mosaicId": "-1412091718288690897",
    "amount": "1",
    "hashAlgorithm": 0,
    "secret": "bLjiXLjIRa9nxZZDpVch4n5yearpsRW33V0U1dG9+VI7d4dZZPnM3XUaPBjL4x2ihOKszgerpH4RQiAwJuXdgQ==",
    "recipient": "kHWOtHwo1hQ7qj3mqNnDGbUDob/Y54np4g=="
  }
}
```

#### 送信後

`foo:bar`がロックされ減った。

|  | Public| Private |
|:--:|:------:|:-------:|
| Alice | 409089866.00019 nem:xem <br /> **99 foo:bar** | 1 nem:xem |
| Bob   | 409090161.99981 nem:xem <br /> 1 foo:bar | 818181817 nem:xem |

```
# node secretlock_disp.js
[1528010897162] Alice(Private) have 1 nem:xem
[1528010897162] Bob(Private) have 818181817 nem:xem
[1528010897162] Bob(Public) have 1 foo:bar
[1528010897162] Bob(Public) have 409090161.99981 nem:xem
[1528010897162] Alice(Public) have 409089866.00019 nem:xem
[1528010897162] Alice(Public) have 99 foo:bar
```

#### 送信後40分経過（期限切れ）

`foo:bar`が返ってきた。

|  | Public| Private |
|:--:|:------:|:-------:|
| Alice | 409089866.00019 nem:xem <br /> **100 foo:bar** | 1 nem:xem |
| Bob   | 409090161.99981 nem:xem <br /> 1 foo:bar | 818181817 nem:xem |

```
# node secretlock_disp.js
[1528013331902] Bob(Public) have 409090161.99981 nem:xem
[1528013331902] Bob(Public) have 1 foo:bar
[1528013331902] Bob(Private) have 818181817 nem:xem
[1528013331902] Alice(Private) have 1 nem:xem
[1528013331902] Alice(Public) have 409089866.00019 nem:xem
[1528013331902] Alice(Public) have 100 foo:bar
```

#### 期限切れ後にsecret proofトランザクションを送信

```
# node secretlock4.js 395d00ab4a2fdd0b5813
tx4Signed.hash   : CBCC6A2F510C6FC55D25F86C5F49180C1C2E49D696BD16462980EAD69CE6DBBF
tx4Signed.signer : 3390BF02D2BB59C8722297FF998CE89183D0906E469873284C091A5CDC22FD57
TransactionAnnounceResponse {
  message: 'packet 9 was pushed to the network via /transaction' }
```

残高は変化せず。

```
# node secretlock_disp.js
[1528014388413] Alice(Private) have 1 nem:xem
[1528014388413] Bob(Private) have 818181817 nem:xem
[1528014388413] Bob(Public) have 1 foo:bar
[1528014388413] Bob(Public) have 409090161.99981 nem:xem
[1528014388413] Alice(Public) have 409089866.00019 nem:xem
[1528014388413] Alice(Public) have 100 foo:bar
```

トランザクションも見つからない。

```
# curl http://localhost:3000/transaction/CBCC6A2F510C6FC55D25F86C5F49180C1C2E49D696BD16462980EAD69CE6DBBF
{"code":"ResourceNotFound","message":"no resource exists with id 'CBCC6A2F510C6FC55D25F86C5F49180C1C2E49D696BD16462980EAD69CE6DBBF'"}
```



# 同じsecretを用いたsecret lockトランザクションを複数送信できるか

答え：複数送信できない

#### 初期状態

|  | Public| Private |
|:--:|:------:|:-------:|
| Alice | 409089866.00019 nem:xem <br /> **98 foo:bar** | 1 nem:xem |
| Bob   | 409090161.99981 nem:xem <br /> 1 foo:bar | 818181817 nem:xem |

```
# node secretlock_disp.js
[1528015239867] Alice(Private) have 1 nem:xem
[1528015239867] Bob(Private) have 818181817 nem:xem
[1528015239867] Alice(Public) have 409089866.00019 nem:xem
[1528015239867] Alice(Public) have 98 foo:bar
[1528015239867] Bob(Public) have 1 foo:bar
[1528015239867] Bob(Public) have 409090161.99981 nem:xem
```

#### 同じproofで複数回送信

`proof=395d00ab4a2fdd0b5815`にして、４回secret lockトランザクションを送信。

```
# node secretlockmulch.js
x    (proof)     : 395d00ab4a2fdd0b5815
H(x) (secret)    : BF370526E5FD221ED267855DDADC6F05D76E46BF722E322643BF76391D5E47C8646AC8FB97E29449DED7852B4B4A40107B059D8705CD29F8EC8535F392870B95
tx1Signed.hash   : FFC0045A36B70AF7EA76CA4A2D836E6E3F5D5F3DC50AFA22B3F54CBC63CE0DE6
tx1Signed.signer : 5D9513282B65A12A1B68DCB67DB64245721F7AE7822BE441FE813173803C512C
TransactionAnnounceResponse {
  message: 'packet 9 was pushed to the network via /transaction' }
tx1Signed.hash   : 28E4CD8096C1BBDB8CFB105ACFC9EB4E31EA0050D4CF81DF8C3629F4AA8AA89A
tx1Signed.signer : 5D9513282B65A12A1B68DCB67DB64245721F7AE7822BE441FE813173803C512C
TransactionAnnounceResponse {
  message: 'packet 9 was pushed to the network via /transaction' }
tx1Signed.hash   : 2B31F94AADD56C43EE9F676BBDEA7A49840331DFA5867144B37539C1A10D7F44
tx1Signed.signer : 5D9513282B65A12A1B68DCB67DB64245721F7AE7822BE441FE813173803C512C
TransactionAnnounceResponse {
  message: 'packet 9 was pushed to the network via /transaction' }
tx1Signed.hash   : E040E9F3305309FB8DAA1C36720FE0EB2122D464665A0AC18C4810F435D74C87
tx1Signed.signer : 5D9513282B65A12A1B68DCB67DB64245721F7AE7822BE441FE813173803C512C
TransactionAnnounceResponse {
  message: 'packet 9 was pushed to the network via /transaction' }
```

#### 残高

１回分しか減っていない

|  | Public| Private |
|:--:|:------:|:-------:|
| Alice | 409089866.00019 nem:xem <br /> **97 foo:bar** | 1 nem:xem |
| Bob   | 409090161.99981 nem:xem <br /> 1 foo:bar | 818181817 nem:xem |

```
# node secretlock_disp.js
[1528015261024] Bob(Private) have 818181817 nem:xem
[1528015261024] Alice(Private) have 1 nem:xem
[1528015261024] Alice(Public) have 97 foo:bar
[1528015261024] Alice(Public) have 409089866.00019 nem:xem
[1528015261024] Bob(Public) have 409090161.99981 nem:xem
[1528015261024] Bob(Public) have 1 foo:bar
```


#### 最初の１回しか存在していない

ハッシュ値でトランザクションを探してみる

```
# curl http://localhost:3000/transaction/FFC0045A36B70AF7EA76CA4A2D836E6E3F5D5F3DC50AFA22B3F54CBC63CE0DE6
{
  "meta": {
    "height": [
      43485,
      0
    ],
    "hash": "FFC0045A36B70AF7EA76CA4A2D836E6E3F5D5F3DC50AFA22B3F54CBC63CE0DE6",
    "merkleComponentHash": "FFC0045A36B70AF7EA76CA4A2D836E6E3F5D5F3DC50AFA22B3F54CBC63CE0DE6",
    "index": 0,
    "id": "5B13AC1980FDB3000135C415"
  },
  "transaction": {
    "signature": "BEB6C3C720750472E4CB219729AEA761CBBE1B79EA9364CB2561EA1E2D9D00CEDC76272D4EB34E7158AAA45F59B7B1963991E8F031AF862631DA33DB33B7CD00",
    "signer": "5D9513282B65A12A1B68DCB67DB64245721F7AE7822BE441FE813173803C512C",
    "version": 36867,
    "type": 16972,
    "fee": [
      0,
      0
    ],
    "deadline": [
      4129135790,
      15
    ],
    "duration": "60",
    "mosaicId": "-1412091718288690897",
    "amount": "1",
    "hashAlgorithm": 0,
    "secret": "vzcFJuX9Ih7SZ4Vd2txvBdduRr9yLjImQ792OR1eR8hkasj7l+KUSd7XhStLSkAQewWdhwXNKfjshTXzkocLlQ==",
    "recipient": "kHWOtHwo1hQ7qj3mqNnDGbUDob/Y54np4g=="
  }
}
```

```
# curl http://localhost:3000/transaction/28E4CD8096C1BBDB8CFB105ACFC9EB4E31EA0050D4CF81DF8C3629F4AA8AA89A
{"code":"ResourceNotFound","message":"no resource exists with id '28E4CD8096C1BBDB8CFB105ACFC9EB4E31EA0050D4CF81DF8C3629F4AA8AA89A'"}
```

```
# curl http://localhost:3000/transaction/2B31F94AADD56C43EE9F676BBDEA7A49840331DFA5867144B37539C1A10D7F44
{"code":"ResourceNotFound","message":"no resource exists with id '2B31F94AADD56C43EE9F676BBDEA7A49840331DFA5867144B37539C1A10D7F44'"}
```

```
# curl http://localhost:3000/transaction/E040E9F3305309FB8DAA1C36720FE0EB2122D464665A0AC18C4810F435D74C87
{"code":"ResourceNotFound","message":"no resource exists with id 'E040E9F3305309FB8DAA1C36720FE0EB2122D464665A0AC18C4810F435D74C87'"}
```


#### モニターしてみる

`Failure_Lock_Hash_Exists`とのこと。同じsecretでは送信しちゃだめというメッセージが。

```
# nem2-cli monitor status --profile alicePub
Monitoring SBWEUW-ON6IBH-CW5IC4-EI6V6S-MTVJGC-JWGLF5-7UGK using http://localhost:3000
connection open

Hash: 28E4CD8096C1BBDB8CFB105ACFC9EB4E31EA0050D4CF81DF8C3629F4AA8AA89A
Error code: Failure_Lock_Hash_Exists
Deadline: 2018-06-03 10:40:47.228

Hash: 2B31F94AADD56C43EE9F676BBDEA7A49840331DFA5867144B37539C1A10D7F44
Error code: Failure_Lock_Hash_Exists
Deadline: 2018-06-03 10:40:49.229

Hash: E040E9F3305309FB8DAA1C36720FE0EB2122D464665A0AC18C4810F435D74C87
Error code: Failure_Lock_Hash_Exists
Deadline: 2018-06-03 10:40:51.229