|
|
@ -5,6 +5,7 @@ |
|
|
|
#include <curl/curl.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <inttypes.h> |
|
|
|
#include <string.h> |
|
|
|
#include "etomiclib.h" |
|
|
|
|
|
|
|
char* bobContractAddress = "0x9387Fd3a016bB0205e4e131Dde886B9d2BC000A2"; |
|
|
@ -36,144 +37,142 @@ int main(int argc, char** argv) |
|
|
|
switch (action) |
|
|
|
{ |
|
|
|
case BOB_ETH_DEPOSIT: |
|
|
|
txData.amount = "1000000000000000000"; |
|
|
|
txData.from = bobAddress; |
|
|
|
txData.to = bobContractAddress; |
|
|
|
txData.secretKey = getenv("BOB_PK"); |
|
|
|
|
|
|
|
BobSendsEthDepositInput input = { |
|
|
|
.aliceAddress = aliceAddress, |
|
|
|
.depositId = argv[2], |
|
|
|
.bobHash = argv[3] |
|
|
|
}; |
|
|
|
strcpy(txData.amount, "1000000000000000000"); |
|
|
|
strcpy(txData.from, bobAddress); |
|
|
|
strcpy(txData.to, bobContractAddress); |
|
|
|
strcpy(txData.secretKey, getenv("BOB_PK")); |
|
|
|
|
|
|
|
BobSendsEthDepositInput input; |
|
|
|
|
|
|
|
strcpy(input.aliceAddress, aliceAddress); |
|
|
|
strcpy(input.depositId, argv[2]); |
|
|
|
strcpy(input.bobHash, argv[3]); |
|
|
|
|
|
|
|
result = bobSendsEthDeposit(input, txData); |
|
|
|
printf("%s\n", result); |
|
|
|
free(result); |
|
|
|
break; |
|
|
|
case BOB_ERC20_DEPOSIT: |
|
|
|
txData.amount = "0"; |
|
|
|
txData.from = bobAddress; |
|
|
|
txData.to = bobContractAddress; |
|
|
|
txData.secretKey = getenv("BOB_PK"); |
|
|
|
strcpy(txData.amount, "0"); |
|
|
|
strcpy(txData.from, bobAddress); |
|
|
|
strcpy(txData.to, bobContractAddress); |
|
|
|
strcpy(txData.secretKey, getenv("BOB_PK")); |
|
|
|
|
|
|
|
BobSendsErc20DepositInput input1 = { |
|
|
|
.depositId = argv[2], |
|
|
|
.amount = "1000000000000000000", |
|
|
|
.aliceAddress = aliceAddress, |
|
|
|
.bobHash = argv[3], |
|
|
|
.tokenAddress = tokenAddress |
|
|
|
.amount = "1000000000000000000" |
|
|
|
}; |
|
|
|
|
|
|
|
strcpy(input1.depositId, argv[2]); |
|
|
|
strcpy(input1.aliceAddress, aliceAddress); |
|
|
|
strcpy(input1.bobHash, argv[3]); |
|
|
|
strcpy(input1.tokenAddress, tokenAddress); |
|
|
|
|
|
|
|
result = bobSendsErc20Deposit(input1, txData); |
|
|
|
printf("%s\n", result); |
|
|
|
free(result); |
|
|
|
break; |
|
|
|
case BOB_CLAIMS_DEPOSIT: |
|
|
|
txData.amount = "0"; |
|
|
|
txData.from = bobAddress; |
|
|
|
txData.to = bobContractAddress; |
|
|
|
txData.secretKey = getenv("BOB_PK"); |
|
|
|
|
|
|
|
BobRefundsDepositInput input2 = { |
|
|
|
.depositId = argv[2], |
|
|
|
.amount = "1000000000000000000", |
|
|
|
.aliceAddress = aliceAddress, |
|
|
|
.tokenAddress = argv[3], |
|
|
|
.aliceCanClaimAfter = argv[4], |
|
|
|
.bobSecret = argv[5] |
|
|
|
}; |
|
|
|
strcpy(txData.amount, "0"); |
|
|
|
strcpy(txData.from, bobAddress); |
|
|
|
strcpy(txData.to, bobContractAddress); |
|
|
|
strcpy(txData.secretKey, getenv("BOB_PK")); |
|
|
|
|
|
|
|
BobRefundsDepositInput input2; |
|
|
|
strcpy(input2.depositId, argv[2]); |
|
|
|
strcpy(input2.amount, "1000000000000000000"); |
|
|
|
strcpy(input2.aliceAddress, aliceAddress); |
|
|
|
strcpy(input2.tokenAddress, argv[3]); |
|
|
|
strcpy(input2.aliceCanClaimAfter, argv[4]); |
|
|
|
strcpy(input2.bobSecret, argv[5]); |
|
|
|
|
|
|
|
result = bobRefundsDeposit(input2, txData); |
|
|
|
printf("%s\n", result); |
|
|
|
free(result); |
|
|
|
break; |
|
|
|
case ALICE_CLAIMS_DEPOSIT: |
|
|
|
txData.amount = "0"; |
|
|
|
txData.from = aliceAddress; |
|
|
|
txData.to = bobContractAddress; |
|
|
|
txData.secretKey = getenv("ALICE_PK"); |
|
|
|
|
|
|
|
AliceClaimsBobDepositInput input3 = { |
|
|
|
.depositId = argv[2], |
|
|
|
.amount = "1000000000000000000", |
|
|
|
.bobAddress = bobAddress, |
|
|
|
.tokenAddress = argv[3], |
|
|
|
.aliceCanClaimAfter = argv[4], |
|
|
|
.bobHash = argv[5] |
|
|
|
}; |
|
|
|
strcpy(txData.amount, "0"); |
|
|
|
strcpy(txData.from, aliceAddress); |
|
|
|
strcpy(txData.to, bobContractAddress); |
|
|
|
strcpy(txData.secretKey, getenv("ALICE_PK")); |
|
|
|
|
|
|
|
AliceClaimsBobDepositInput input3; |
|
|
|
strcpy(input3.depositId, argv[2]); |
|
|
|
strcpy(input3.amount, "1000000000000000000"); |
|
|
|
strcpy(input3.bobAddress, bobAddress); |
|
|
|
strcpy(input3.tokenAddress, argv[3]); |
|
|
|
strcpy(input3.aliceCanClaimAfter, argv[4]); |
|
|
|
strcpy(input3.bobHash, argv[5]); |
|
|
|
|
|
|
|
result = aliceClaimsBobDeposit(input3, txData); |
|
|
|
printf("%s\n", result); |
|
|
|
free(result); |
|
|
|
break; |
|
|
|
case BOB_ETH_PAYMENT: |
|
|
|
txData.amount = "1000000000000000000"; |
|
|
|
txData.from = bobAddress; |
|
|
|
txData.to = bobContractAddress; |
|
|
|
txData.secretKey = getenv("BOB_PK"); |
|
|
|
|
|
|
|
BobSendsEthPaymentInput input4 = { |
|
|
|
.paymentId = argv[2], |
|
|
|
.aliceHash = argv[3], |
|
|
|
.aliceAddress = aliceAddress |
|
|
|
}; |
|
|
|
strcpy(txData.amount, "1000000000000000000"); |
|
|
|
strcpy(txData.from, bobAddress); |
|
|
|
strcpy(txData.to, bobContractAddress); |
|
|
|
strcpy(txData.secretKey, getenv("BOB_PK")); |
|
|
|
|
|
|
|
BobSendsEthPaymentInput input4; |
|
|
|
strcpy(input4.paymentId, argv[2]); |
|
|
|
strcpy(input4.aliceHash, argv[3]); |
|
|
|
strcpy(input4.aliceAddress, aliceAddress); |
|
|
|
|
|
|
|
result = bobSendsEthPayment(input4, txData); |
|
|
|
printf("%s\n", result); |
|
|
|
free(result); |
|
|
|
break; |
|
|
|
case BOB_ERC20_PAYMENT: |
|
|
|
txData.amount = "0"; |
|
|
|
txData.from = bobAddress; |
|
|
|
txData.to = bobContractAddress; |
|
|
|
txData.secretKey = getenv("BOB_PK"); |
|
|
|
|
|
|
|
BobSendsErc20PaymentInput input5 = { |
|
|
|
.paymentId = argv[2], |
|
|
|
.amount = "1000000000000000000", |
|
|
|
.tokenAddress = tokenAddress, |
|
|
|
.aliceAddress = aliceAddress, |
|
|
|
.aliceHash = argv[3] |
|
|
|
}; |
|
|
|
strcpy(txData.amount, "0"); |
|
|
|
strcpy(txData.from, bobAddress); |
|
|
|
strcpy(txData.to, bobContractAddress); |
|
|
|
strcpy(txData.secretKey, getenv("BOB_PK")); |
|
|
|
|
|
|
|
BobSendsErc20PaymentInput input5; |
|
|
|
|
|
|
|
strcpy(input5.paymentId, argv[2]); |
|
|
|
strcpy(input5.amount, "1000000000000000000"); |
|
|
|
strcpy(input5.tokenAddress, tokenAddress); |
|
|
|
strcpy(input5.aliceAddress, aliceAddress); |
|
|
|
strcpy(input5.aliceHash, argv[3]); |
|
|
|
|
|
|
|
result = bobSendsErc20Payment(input5, txData); |
|
|
|
printf("%s\n", result); |
|
|
|
free(result); |
|
|
|
break; |
|
|
|
case BOB_CLAIMS_PAYMENT: |
|
|
|
txData.amount = "0"; |
|
|
|
txData.from = bobAddress; |
|
|
|
txData.to = bobContractAddress; |
|
|
|
txData.secretKey = getenv("BOB_PK"); |
|
|
|
|
|
|
|
BobReclaimsBobPaymentInput input6 = { |
|
|
|
.paymentId = argv[2], |
|
|
|
.aliceAddress = aliceAddress, |
|
|
|
.amount = "1000000000000000000", |
|
|
|
.tokenAddress = argv[3], |
|
|
|
.bobCanClaimAfter = argv[4], |
|
|
|
.aliceHash = argv[5] |
|
|
|
}; |
|
|
|
strcpy(txData.amount, "0"); |
|
|
|
strcpy(txData.from, bobAddress); |
|
|
|
strcpy(txData.to, bobContractAddress); |
|
|
|
strcpy(txData.secretKey, getenv("BOB_PK")); |
|
|
|
|
|
|
|
BobReclaimsBobPaymentInput input6; |
|
|
|
|
|
|
|
strcpy(input6.paymentId, argv[2]); |
|
|
|
strcpy(input6.aliceAddress, aliceAddress); |
|
|
|
strcpy(input6.amount, "1000000000000000000"); |
|
|
|
strcpy(input6.tokenAddress, argv[3]); |
|
|
|
strcpy(input6.bobCanClaimAfter, argv[4]); |
|
|
|
strcpy(input6.aliceHash, argv[5]); |
|
|
|
|
|
|
|
result = bobReclaimsBobPayment(input6, txData); |
|
|
|
printf("%s\n", result); |
|
|
|
free(result); |
|
|
|
break; |
|
|
|
case ALICE_CLAIMS_PAYMENT: |
|
|
|
txData.amount = "0"; |
|
|
|
txData.from = aliceAddress; |
|
|
|
txData.to = bobContractAddress; |
|
|
|
txData.secretKey = getenv("ALICE_PK"); |
|
|
|
|
|
|
|
AliceSpendsBobPaymentInput input7 = { |
|
|
|
.paymentId = argv[2], |
|
|
|
.bobAddress = bobAddress, |
|
|
|
.amount = "1000000000000000000", |
|
|
|
.tokenAddress = argv[3], |
|
|
|
.bobCanClaimAfter = argv[4], |
|
|
|
.aliceSecret = argv[5] |
|
|
|
}; |
|
|
|
strcpy(txData.amount, "0"); |
|
|
|
strcpy(txData.from, aliceAddress); |
|
|
|
strcpy(txData.to, bobContractAddress); |
|
|
|
strcpy(txData.secretKey, getenv("ALICE_PK")); |
|
|
|
|
|
|
|
AliceSpendsBobPaymentInput input7; |
|
|
|
|
|
|
|
strcpy(input7.paymentId, argv[2]); |
|
|
|
strcpy(input7.bobAddress, bobAddress); |
|
|
|
strcpy(input7.amount, "1000000000000000000"); |
|
|
|
strcpy(input7.tokenAddress, argv[3]); |
|
|
|
strcpy(input7.bobCanClaimAfter, argv[4]); |
|
|
|
strcpy(input7.aliceSecret, argv[5]); |
|
|
|
|
|
|
|
result = aliceSpendsBobPayment(input7, txData); |
|
|
|
printf("%s\n", result); |
|
|
@ -198,5 +197,19 @@ int main(int argc, char** argv) |
|
|
|
default: |
|
|
|
return 1; |
|
|
|
} |
|
|
|
char *pubkey = getPubKeyFromPriv(getenv("BOB_PK")); |
|
|
|
printf("pubkey: %s\n", pubkey); |
|
|
|
free(pubkey); |
|
|
|
uint8_t test[2]; |
|
|
|
test[0] = 100; |
|
|
|
test[1] = 100; |
|
|
|
char buf[30]; |
|
|
|
uint8arrayToHex(buf, test, 2); |
|
|
|
printf("hex: %s\n", buf); |
|
|
|
|
|
|
|
uint64_t satoshis = 100000000; |
|
|
|
char weiBuffer[100]; |
|
|
|
satoshisToWei(weiBuffer, satoshis); |
|
|
|
printf("wei: %s\n", weiBuffer); |
|
|
|
return 0; |
|
|
|
} |
|
|
|