-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 40c812c
Showing
92 changed files
with
14,793 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VUE_APP_ENV=test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VUE_APP_ENV=extension |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.DS_Store | ||
node_modules | ||
/dist | ||
/local | ||
/lib | ||
public/manifest.json | ||
public/js | ||
3rdpage/js | ||
|
||
|
||
# local env files | ||
.env.local | ||
.env.*.local | ||
|
||
# Log files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
|
||
# Editor directories and files | ||
.idea | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vendor | ||
node_modules | ||
local | ||
dist | ||
lib | ||
public/js | ||
public/manifest.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="styles.css" /> | ||
</head> | ||
<body> | ||
<h2>Koinos coin flipper</h2> | ||
|
||
<div class="group"> | ||
<table> | ||
<tr> | ||
<td><label for="address">Address:</label></td> | ||
<td><input id="address" type="text" readonly="readonly" onclick="accountHelp()" size="45"/></td> | ||
<td><button onclick="getAccounts()">Choose account</button></td> | ||
</tr> | ||
<tr> | ||
<td><label for="wager">Wager:</label></td> | ||
<td><input id="wager" type="number" /></td> | ||
<td></td> | ||
</tr> | ||
<tr> | ||
<td><label for="value">Bet:</label></td> | ||
<td><select name="value" id="value"><option value="heads">Heads</option><option value="tails">Tails</option></select></td> | ||
</tr> | ||
</table> | ||
<div><button onclick="flip()">Flip coin!</button></div> | ||
<!-- <table> | ||
<tr> | ||
<td><button onclick="flip()">Flip</button></td> | ||
</tr> | ||
</table> --> | ||
</div> | ||
<div id="result"></div> | ||
<script src="js/kondor.min.js"></script> | ||
<script src="js/koinos.min.js"></script> | ||
<script> | ||
const inputAddress = document.getElementById("address"); | ||
const inputWager = document.getElementById("wager"); | ||
const inputValue = document.getElementById("value"); | ||
const elResult = document.getElementById("result"); | ||
|
||
const koin = new Contract({ | ||
id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ", | ||
abi: utils.tokenAbi, | ||
provider: kondor.provider, | ||
signer: kondor.getSigner(inputAddress.value), | ||
}).functions; | ||
|
||
const divResult = { | ||
hide: () => elResult.setAttribute("style", "display:none;"), | ||
show: (msg) => { | ||
elResult.innerHTML = msg; | ||
elResult.setAttribute("style", "display:block;"); | ||
}, | ||
}; | ||
divResult.hide(); | ||
|
||
async function accountHelp() { | ||
divResult.show(`Use the 'Choose account' button to select the address`); | ||
} | ||
|
||
async function getAccounts() { | ||
divResult.hide(); | ||
try { | ||
const accounts = await kondor.getAccounts(); | ||
console.log(accounts); | ||
if (accounts.length > 0) { | ||
inputAddress.value = accounts[0].address; | ||
const { result } = await koin.balanceOf({ owner: accounts[0].address }); | ||
console.log(result); | ||
let myBalance = (result.value / 100000000).toFixed(8); | ||
divResult.show(`Account balance: ${myBalance}`); | ||
} | ||
//divResult.show(`Accounts: ${JSON.stringify(accounts)}`); | ||
} catch (error) { | ||
divResult.show(`Error: ${error.message}`); | ||
console.error(error); | ||
} | ||
} | ||
|
||
async function flip() { | ||
const gambleAbi = { | ||
methods: { | ||
flip: { | ||
entry_point: 0x4e448897, | ||
argument: "gamble.flip_arguments", | ||
return: "gamble.flip_result", | ||
read_only: false, | ||
}, | ||
}, | ||
koilib_types: { | ||
nested: { | ||
gamble: { | ||
nested: { | ||
flip_arguments: { | ||
fields: { | ||
address: { | ||
type: "bytes", | ||
id: 1, | ||
options: { | ||
"(koinos.btype)": "ADDRESS" | ||
} | ||
}, | ||
wager: { | ||
type: "uint64", | ||
id: 2, | ||
options: { | ||
"jstype": "JS_STRING" | ||
} | ||
}, | ||
heads: { | ||
type: "bool", | ||
id: 3 | ||
} | ||
} | ||
}, | ||
flip_result: { | ||
fields: {} | ||
}, | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
divResult.hide(); | ||
try { | ||
// contract definition | ||
const gamble = new Contract({ | ||
id: "1PyX2kxxNrp53JTSqcpKpkWneQCdZGCkoc", | ||
abi: gambleAbi, | ||
provider: kondor.provider, | ||
signer: kondor.getSigner(inputAddress.value), | ||
}).functions; | ||
|
||
// transfer | ||
const { transaction, receipt } = await gamble.flip( | ||
{ | ||
address: inputAddress.value, | ||
wager: inputWager.value, | ||
heads: inputValue.value == "heads" ? true : false, | ||
}, | ||
{ | ||
payer: inputAddress.value, | ||
} | ||
); | ||
console.log(`Transaction ${transaction.id} submitted. Receipt:`); | ||
console.log(receipt); | ||
|
||
if (receipt.logs) throw new Error(receipt.logs.join(", ")); | ||
|
||
divResult.show( | ||
`Transaction ${transaction.id} submitted. <br/>Waiting to be mined...` | ||
); | ||
|
||
// wait to be mined | ||
const blockNumber = await transaction.wait(); | ||
console.log(`Mined in block ${blockNumber}`); | ||
divResult.show( | ||
`Transaction <a href="https://koinosexplorer.com/tx/${transaction.id}" target="_blank">${transaction.id}</a> submitted. <br/>Mined in block <a href="https://koinosexplorer.com/block/${blockNumber}" target="_blank">${blockNumber}</a>"...` | ||
); | ||
|
||
// read the balance | ||
const { result } = await koin.balanceOf({ owner: inputAddress.value }); | ||
console.log(result); | ||
let myBalance = result.value / 100000000; | ||
divResult.show( | ||
`Transaction <a href="https://koinosexplorer.com/tx/${transaction.id}" target="_blank">${transaction.id}</a> submitted. <br/>Mined in block <a href="https://koinosexplorer.com/block/${blockNumber}" target="_blank">${blockNumber}</a>. <br/>New balance ${myBalance} tKOIN.` | ||
); | ||
|
||
const head = await kondor.provider.getHeadInfo(); | ||
let headId = head.head_topology.id; | ||
let params = { | ||
head_block_id: headId, | ||
ancestor_start_height: blockNumber, | ||
num_blocks: 1, | ||
return_block: false, | ||
return_receipt: true | ||
} | ||
const rpcResponse = await kondor.provider.call("block_store.get_blocks_by_height", params); | ||
console.log(rpcResponse); | ||
|
||
let blockItems = rpcResponse.block_items; | ||
|
||
for (let i = 0; i < blockItems.length; i++) { | ||
for (let j = 0; j < blockItems[i].receipt.transaction_receipts.length; j++) { | ||
if (blockItems[i].receipt.transaction_receipts[j].id == transaction.id) { | ||
if (blockItems[i].receipt.transaction_receipts[j].events.length == 1) { | ||
if (blockItems[i].receipt.transaction_receipts[j].events[0].name == "koin.transfer") { | ||
let serializer = new Serializer(utils.tokenAbi.koilib_types); | ||
let transferEvent = serializer.deserialize(blockItems[i].receipt.transaction_receipts[j].events[0].data, "koinos.contracts.token.transfer_event", {bytesConversion: true}); | ||
console.log(blockItems[i].receipt.transaction_receipts[j].events[0].data); | ||
console.log(transferEvent); | ||
|
||
transferEvent.then((result) => { | ||
let resultMessage = ""; | ||
if (result.to === inputAddress.value) { | ||
resultMessage = "You've won "; | ||
} | ||
else { | ||
resultMessage = "You've lost "; | ||
} | ||
let winnings = (result.value / 100000000).toFixed(8); | ||
resultMessage += `${winnings} tKOIN.`; | ||
divResult.show(`Transaction <a href="https://koinosexplorer.com/tx/${transaction.id}" target="_blank">${transaction.id}</a> submitted. <br/>Mined in block <a href="https://koinosexplorer.com/block/${blockNumber}" target="_blank">${blockNumber}</a>. <br/>New balance ${myBalance} tKOIN. <br/>${resultMessage}`); | ||
}); | ||
} | ||
else { | ||
throw Error('Only event should be a KOIN transfer'); | ||
} | ||
} | ||
else { | ||
throw Error('Should only be 1 event'); | ||
} | ||
} | ||
else { | ||
throw Error('Transaction ID mismatch'); | ||
} | ||
} | ||
} | ||
} catch (error) { | ||
divResult.show(`Error: ${error.message}`); | ||
console.error(error); | ||
} | ||
} | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
body { | ||
font-family: sans-serif; | ||
} | ||
|
||
.group { | ||
margin-top: 30px; | ||
} | ||
|
||
#result { | ||
margin-top: 30px; | ||
width: 100%; | ||
padding: 8px 20px; | ||
border-radius: 8px; | ||
box-sizing: border-box; | ||
background-color: rgb(224, 224, 224); | ||
} | ||
|
||
table { | ||
border:1px solid gray; | ||
margin-left:auto; | ||
margin-right:auto; | ||
padding: 5px; | ||
margin-bottom: 5px; | ||
margin-top: 5px; | ||
} | ||
h1, h2 {text-align: center;} | ||
p {text-align: center;} | ||
div {text-align: center;} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Julián González @joticajulian | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.