Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cosigner support for WCW and Anchor #233

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 52 additions & 62 deletions store/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,10 @@ export const actions = {
enough_cpu = false
}

let cosignpayer = ''
let index = 0
let enough_bank_wax = false
let ms = 1
if (actions[0].data.to == 'alcorammswap') {
cosignpayer = 'alcorammswap'
index = 1
}
if (actions[0].data.to == 'alcordexmain') {
cosignpayer = 'alcordexmain'
index = 0
ms = 2
}
let cosignpayer = 'alcordexmain'
let ms = 2
try {
const bank_wax = await rpcWAX.get_table_rows({
json: true, // Get the response as json
Expand Down Expand Up @@ -313,66 +304,65 @@ export const actions = {
],
}
actions = [cosign, cosignpay, ...actions]
if (state.currentWallet == 'anchor') {
const transaction = await apiWAX.transact(
{
max_cpu_usage_ms: ms,
max_net_usage_words: 1000 * ms,
actions,
},
{
broadcast: false,
sign: false,
blocksBehind: 5,
expireSeconds: 1200,
}
)
const deserializedTransaction = await apiWAX.deserializeTransaction(
transaction.serializedTransaction
)
const abis = await apiWAX.getTransactionAbis(
deserializedTransaction
const transaction = await apiWAX.transact(
{
max_cpu_usage_ms: ms,
max_net_usage_words: 1000 * ms,
actions,
},
{
broadcast: false,
sign: false,
blocksBehind: 5,
expireSeconds: 1200,
}
)
const deserializedTransaction = await apiWAX.deserializeTransaction(
transaction.serializedTransaction
)
const serializedContextFreeData =
await apiWAX.serializeContextFreeData(
deserializedTransaction.context_free_data
)
const serializedContextFreeData =
await apiWAX.serializeContextFreeData(
deserializedTransaction.context_free_data
)
const serializedTransaction = transaction.serializedTransaction

const chainId = rootState.network.chainId
const requiredKeys =
await getters.wallet.sessionProvider.getAvailableKeys()
const serializedTransaction = transaction.serializedTransaction
const signedTransaction = await getters.wallet.sign(
deserializedTransaction
)
const request = {
transaction: Array.from(serializedTransaction),
}

const request = {
transaction: Array.from(serializedTransaction),
const response = await fetch(
rootState.network.LIMITLESS_WAX_ENDPOINT + 'cpu-rent',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(request),
}
)

const response = await fetch(
rootState.network.LIMITLESS_WAX_ENDPOINT + 'cpu-rent',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(request),
}
)
if (!response.ok) {
const body = await response.json()
console.log(body.reason || 'Failed to connect to endpoint')
return await getters.wallet.transact(original_actions)
}

if (!response.ok) {
const body = await response.json()
throw new Error(body.reason || 'Failed to connect to endpoint')
}
const json = await response.json()

const json = await response.json()
if (!json.isOk) {
console.log(json.reason)
return await getters.wallet.transact(original_actions)
}

if (!json.isOk) {
throw new Error(json.reason)
}
if (json.signature == 'limit reached') {
return await getters.wallet.transact(original_actions)
}

if (state.currentWallet == 'anchor') {
const signedTransaction = await getters.wallet.sign(
deserializedTransaction
)
const sigs = []
if (json.signature) {
sigs.push(json.signature[0])
Expand Down