Skip to content

Commit

Permalink
feat: stateQuery, submitTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
vaultec81 committed Dec 1, 2023
1 parent 4de1509 commit 740e246
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 162 deletions.
175 changes: 17 additions & 158 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"peer-id": "^0.16.0",
"regtest-client": "^0.2.1",
"shuffle-seed": "^1.1.6",
"sift": "^17.0.1",
"tiny-secp256k1": "^2.2.3",
"uuid": "^8.3.2",
"varuint-bitcoin": "^1.1.2",
Expand Down
66 changes: 63 additions & 3 deletions src/modules/api/graphql/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CID } from 'multiformats'
import { appContainer } from '../index'
import { GraphQLError } from 'graphql';
import * as IPFS from 'kubo-rpc-client'
import sift from 'sift'
import { TransactionDbStatus, TransactionDbType } from '../../../types';

export const DebugResolvers = {
Expand Down Expand Up @@ -61,9 +62,10 @@ export const Resolvers = {
stateKeys: async (args) => {
try {
let key = args.key ? `${args.key}` : null
const obj2 = await appContainer.self.ipfs.dag.get(CID.parse(data.state_merkle), {
const objCid = await appContainer.self.ipfs.dag.resolve(CID.parse(data.state_merkle), {
path: key,
})
const obj2 = await appContainer.self.ipfs.dag.get(objCid.cid)
if(obj2.value.Links) {
return obj2.value.Links.map(e => {
return {
Expand All @@ -74,7 +76,36 @@ export const Resolvers = {
} else {
return []
}
} catch {
} catch(ex) {
console.log(ex)
return null;
}
},
stateQuery: async (args) => {
try {
let key = args.key ? `${args.key}` : null
const objCid = await appContainer.self.ipfs.dag.resolve(CID.parse(data.state_merkle), {
path: key,
})
const obj2 = await appContainer.self.ipfs.dag.get(objCid.cid)
if(obj2.value.Links) {
const out = await Promise.all(obj2.value.Links.map(e => {
return e.Hash
}).map(async (e) => {
return (await appContainer.self.ipfs.dag.get(e)).value
}));

// console.log(out, args.query)
if(args.query) {
return out.filter(sift(args.query))
} else {
return out
}
} else {
return []
}
} catch(ex) {
console.log(ex)
return null;
}
},
Expand Down Expand Up @@ -208,6 +239,7 @@ export const Resolvers = {
txs: out.map(e => {
return {
...e,
first_seen: e.first_seen.toISOString(),
redeem: async () => {
if((e as any).decoded_tx.op_cateogry !== "wrap_redeem") {
return null
Expand Down Expand Up @@ -325,6 +357,34 @@ export const Resolvers = {
}
},
submitTransaction: async (_, args) => {

console.log(args.payload)
const json = JSON.parse(args.payload)


if(json.jws && json.linkedBlock) {
const root = await appContainer.self.ipfs.dag.put({
...json.jws,
link: CID.parse(json.jws['link'].toString()) //Glich with dag.put not allowing CIDs to link
})

const linkedBlock = await appContainer.self.ipfs.block.put(Buffer.from(json.linkedBlock, 'base64'), {
format: 'dag-cbor'
})
console.log('graphql:linkedBlock', linkedBlock)

await appContainer.self.transactionPool.processMempoolTX(root.toString())


await appContainer.self.p2pService.memoryPoolChannel.call('announce_tx', {
payload: {
id: root.toString()
},
mode: 'basic'
})

return {
tx_id: root.toString()
}
}
}
}
Loading

0 comments on commit 740e246

Please sign in to comment.