Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
86904fb2
Commit
86904fb2
authored
Feb 25, 2023
by
Will Cory
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix write
parent
87efbc2a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
2 deletions
+41
-2
cli.ts
packages/atst/src/cli.ts
+20
-1
write.ts
packages/atst/src/commands/write.ts
+21
-1
No files found.
packages/atst/src/cli.ts
View file @
86904fb2
...
@@ -6,7 +6,7 @@ import { readOptionsValidators, ReadOptions } from './commands/read'
...
@@ -6,7 +6,7 @@ import { readOptionsValidators, ReadOptions } from './commands/read'
import
*
as
logger
from
'
./lib/logger
'
import
*
as
logger
from
'
./lib/logger
'
// @ts-ignore it's mad about me importing something not in tsconfig.includes
// @ts-ignore it's mad about me importing something not in tsconfig.includes
import
packageJson
from
'
../package.json
'
import
packageJson
from
'
../package.json
'
import
{
writeOptionsValidators
}
from
'
./commands/write
'
import
{
WriteOptions
,
writeOptionsValidators
}
from
'
./commands/write
'
const
cli
=
cac
(
'
atst
'
)
const
cli
=
cac
(
'
atst
'
)
...
@@ -51,6 +51,9 @@ cli
...
@@ -51,6 +51,9 @@ cli
'
--private-key <string>
'
,
'
--private-key <string>
'
,
writeOptionsValidators
.
privateKey
.
description
!
writeOptionsValidators
.
privateKey
.
description
!
)
)
.
option
(
'
--data-type [string]
'
,
readOptionsValidators
.
dataType
.
description
!
,
{
default
:
writeOptionsValidators
.
dataType
.
parse
(
undefined
),
})
.
option
(
'
--about <string>
'
,
writeOptionsValidators
.
about
.
description
!
)
.
option
(
'
--about <string>
'
,
writeOptionsValidators
.
about
.
description
!
)
.
option
(
'
--key <string>
'
,
writeOptionsValidators
.
key
.
description
!
)
.
option
(
'
--key <string>
'
,
writeOptionsValidators
.
key
.
description
!
)
.
option
(
'
--value <string>
'
,
writeOptionsValidators
.
value
.
description
!
)
.
option
(
'
--value <string>
'
,
writeOptionsValidators
.
value
.
description
!
)
...
@@ -68,6 +71,22 @@ cli
...
@@ -68,6 +71,22 @@ cli
()
=>
()
=>
`atst write --key "optimist.base-uri" --about 0x2335022c740d17c2837f9C884Bfe4fFdbf0A95D5 --value "my attestation" --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545`
`atst write --key "optimist.base-uri" --about 0x2335022c740d17c2837f9C884Bfe4fFdbf0A95D5 --value "my attestation" --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545`
)
)
.
action
(
async
(
options
:
WriteOptions
)
=>
{
const
{
write
}
=
await
import
(
'
./commands/write
'
)
// TODO use the native api to do this instead of parsing the raw args
// by default options parses addresses as numbers without precision
// we should use the args parsing library to do this directly
// but for now I didn't bother to figure out how to do that
const
{
rawArgs
}
=
cli
const
privateKey
=
rawArgs
[
rawArgs
.
indexOf
(
'
--private-key
'
)
+
1
]
as
Address
const
about
=
rawArgs
[
rawArgs
.
indexOf
(
'
--about
'
)
+
1
]
as
Address
const
contract
=
rawArgs
.
includes
(
'
--contract
'
)
?
(
rawArgs
[
rawArgs
.
indexOf
(
'
--contract
'
)
+
1
]
as
Address
)
:
options
.
contract
await
write
({
...
options
,
about
,
privateKey
,
contract
})
})
cli
.
help
()
cli
.
help
()
cli
.
version
(
packageJson
.
version
)
cli
.
version
(
packageJson
.
version
)
...
...
packages/atst/src/commands/write.ts
View file @
86904fb2
...
@@ -9,6 +9,7 @@ import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddr
...
@@ -9,6 +9,7 @@ import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddr
import
{
DEFAULT_RPC_URL
}
from
'
../constants/defaultRpcUrl
'
import
{
DEFAULT_RPC_URL
}
from
'
../constants/defaultRpcUrl
'
import
{
prepareWriteAttestation
}
from
'
../lib/prepareWriteAttestation
'
import
{
prepareWriteAttestation
}
from
'
../lib/prepareWriteAttestation
'
import
{
writeAttestation
}
from
'
../lib/writeAttestation
'
import
{
writeAttestation
}
from
'
../lib/writeAttestation
'
import
{
dataTypeOptionValidator
}
from
'
../types/DataTypeOption
'
const
zodAddress
=
()
=>
const
zodAddress
=
()
=>
z
z
...
@@ -27,6 +28,7 @@ export const writeOptionsValidators = {
...
@@ -27,6 +28,7 @@ export const writeOptionsValidators = {
.
string
()
.
string
()
.
describe
(
'
Key of the attestation either as string or hex number
'
),
.
describe
(
'
Key of the attestation either as string or hex number
'
),
value
:
zodAttestation
().
describe
(
'
Attestation value
'
).
default
(
''
),
value
:
zodAttestation
().
describe
(
'
Attestation value
'
).
default
(
''
),
dataType
:
dataTypeOptionValidator
,
rpcUrl
:
z
rpcUrl
:
z
.
string
()
.
string
()
.
url
()
.
url
()
...
@@ -80,11 +82,29 @@ export const write = async (options: WriteOptions) => {
...
@@ -80,11 +82,29 @@ export const write = async (options: WriteOptions) => {
}),
}),
})
})
const
castAsDataType
=
(
value
:
any
)
=>
{
if
(
parsedOptions
.
dataType
===
'
string
'
)
{
return
value
}
else
if
(
parsedOptions
.
dataType
===
'
number
'
)
{
return
Number
(
value
)
}
else
if
(
parsedOptions
.
dataType
===
'
bool
'
)
{
return
Boolean
(
value
)
}
else
if
(
parsedOptions
.
dataType
===
'
bytes
'
)
{
return
value
}
else
if
(
parsedOptions
.
dataType
===
'
address
'
)
{
return
value
}
else
{
throw
new
Error
(
`Unrecognized data type
${
parsedOptions
.
dataType
satisfies
never
}
`
)
}
}
try
{
try
{
const
preparedTx
=
await
prepareWriteAttestation
(
const
preparedTx
=
await
prepareWriteAttestation
(
parsedOptions
.
about
,
parsedOptions
.
about
,
parsedOptions
.
key
,
parsedOptions
.
key
,
parsedOptions
.
value
,
castAsDataType
(
parsedOptions
.
value
)
,
network
.
chainId
network
.
chainId
)
)
const
result
=
await
writeAttestation
(
preparedTx
)
const
result
=
await
writeAttestation
(
preparedTx
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment