Created
September 8, 2018 11:53
-
-
Save digitalronin/7329f163a42403cc6bece33cf68bffaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This works ---------------------------- | |
NB: shell variables are replaced with their | |
values before 'uplink_create_contract' | |
is called. | |
*/ | |
global account david = u'${DAVID_ADDRESS}'; | |
global account charlie = u'${CHARLIE_ADDRESS}'; | |
global assetDisc usd = a'${USD_ASSET_ADDRESS}'; | |
global assetDisc assetAddress = a'${VIOLIN_ADDRESS}'; | |
global int usdAmount; | |
global int numTokens; | |
transition initial -> loop; | |
transition loop -> loop; | |
transition loop -> terminal; | |
@initial {david} | |
start() { | |
transitionTo(:loop); | |
} | |
@loop {charlie} | |
execute(int usdValue, int tokenAmount) { | |
usdAmount = usdValue; | |
transferTo(usd, usdAmount); | |
numTokens = tokenAmount; | |
transferHoldings(david, assetAddress, numTokens, charlie); | |
transferFrom(usd, usdAmount, david); | |
transitionTo(:loop); | |
} | |
@loop {david} | |
terminate() { | |
transitionTo(:terminal); | |
} | |
### Given the contract above, I can call it like this to swap | |
### one violin token for one USD cent; | |
result = rpc.uplink_call_contract( | |
private_key = privkey, | |
from_address = account_address, | |
contract_addr = contract_address, | |
method = 'execute', | |
args = [VInt(1), VInt(1)] | |
) | |
### I want to pass in the asset, buyer and seller addresses, | |
### so to try and pass in the asset address, I modified the | |
### contract like this; | |
global account david = u'${DAVID_ADDRESS}'; | |
global account charlie = u'${CHARLIE_ADDRESS}'; | |
global assetDisc usd = a'${USD_ASSET_ADDRESS}'; | |
global assetDisc assetAddress; | |
global int usdAmount; | |
global int numTokens; | |
transition initial -> loop; | |
transition loop -> loop; | |
transition loop -> terminal; | |
@initial {david} | |
start() { | |
transitionTo(:loop); | |
} | |
@loop {charlie} | |
execute(int usdValue, assetDisc astAddr, int tokenAmount) { | |
usdAmount = usdValue; | |
transferTo(usd, usdAmount); | |
assetAddress = astAddr; | |
numTokens = tokenAmount; | |
transferHoldings(david, assetAddress, numTokens, charlie); | |
transferFrom(usd, usdAmount, david); | |
transitionTo(:loop); | |
} | |
@loop {david} | |
terminate() { | |
transitionTo(:terminal); | |
} | |
### Then tried to call it like this; | |
result = rpc.uplink_call_contract( | |
private_key = privkey, | |
from_address = account_address, | |
contract_addr = contract_address, | |
method = 'execute', | |
args = [VInt(1), VAsset(asset_address), VInt(1)] | |
) | |
### The call fails, and in the logs I can see this error; | |
[2018-09-08T11:38:58.950+00:00] (Messaging) Could not verify transaction with signature: Base64PByteString {unbase64P = "AE0zMDE5NjQ3ODI5ODI1Nzg1MTczNjQ4OTY3NDI3NjAxNzY5MzcxMDE5MTMzOTcxNDc3NjI3MjczNDkzOTgyNTg0MTc2OTQyNDIxODExNToATTgzMTg2ODM5OTA3MTE2OTQzMDYyNjk5Mjk1MjM4MzU3Njk0MjQzNTMwODA3ODE0NDk5OTg2NzA0OTIyNzc2MDEyODc2Nzc1ODk3NTc4"} due to: InvalidTransaction {transaction = Transaction {header = TxContract (Call {address = Address "5naLArqVf6yoFjLHJg2wQPQRoFaehSHiqg4qgYrb56Ya", method = "execute", args = [VInt 1,VAsset (Address "3D76xmFJffT4CyRx8vcypj3yKHoTLvPwKP9sk5gaShkX"),VInt 1]}), signature = Base64PByteString {unbase64P = "AE0zMDE5NjQ3ODI5ODI1Nzg1MTczNjQ4OTY3NDI3NjAxNzY5MzcxMDE5MTMzOTcxNDc3NjI3MjczNDkzOTgyNTg0MTc2OTQyNDIxODExNToATTgzMTg2ODM5OTA3MTE2OTQzMDYyNjk5Mjk1MjM4MzU3Njk0MjQzNTMwODA3ODE0NDk5OTg2NzA0OTIyNzc2MDEyODc2Nzc1ODk3NTc4"}, origin = Address "2PeARE8xv4w2PTqrhPd3ag1b41FnbQRoVCXvWd5tDE4C"}, reason = InvalidTxField (InvalidTxSignature (InvalidSignature (Signature {sign_r = 30196478298257851736489674276017693710191339714776272734939825841769424218115, sign_s = 83186839907116943062699295238357694243530807814499986704922776012876775897578}) "\NUL\NUL\NUL\STXG\ESC\146\&0M9\v[O\219\219\165V\187\176\250O\SUB\219\NAK\151\188\131\f\134sU\b\141\156\246{\NUL\NUL\NUL\NUL\NUL\NUL\NUL\aexecute\NUL\NUL\NUL\NUL\NUL\NUL\NUL\ETX\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\SOH\ACK \209>v\211MH\r\239Ll7W(\192\ESC\155u\ESC\SUB>\CAN\186\219\254\255D\n\175\&3FT\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\SOH"))} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment