Input file for Script
- star123goodOP
I’ve a script like the follwing
upgradeInven : Party → [InvenKey] → [Int] → Script ()
And, I hope to run this script
daml script --dar $(dar_path) --script-name Scripts.InitializeScript:upgradeInven --ledger-host $(ledger_host) --ledger-port $(ledger_port) --input-file exclude-keys.jsonHow can I build
exclude-keys.jsonto run the script? - Mate_Varga
Hi @star123good,
Please note this section from our documentation:
If the
--input-fileflag is specified, the--script-nameflag must point to a function of one argument returning aScript, and the function will be called with the result of parsing the input file as its argument. For example, we can initialize our ledger using theinitializefunction defined above.So to be able to use the
--input-fileoption, first you need to define a data type that encapsulates all your arguments. The easiest way to generate the json is to do it from another daml script which populates and returns an instance of that same data type, using the--output-fileoption. - star123good
Hi, @Mate_Varga
data UpgradeData = UpgradeData with
operator : Party
invenkeys : [InvenKey]
nums: [Int]upgradeInven : UpgradeData→ Script ()
And, in exclude-keys.json
{
“operator”: “Operator”,
“invenkeys”: ,
“nums”:
}Is this correct?
- Mate_Varga
Hi @star123good,
I recommend you run a script just to produce an example, but basically yes.
I have mocked up your type and ran it to produce an output:data InvenKey = InvenKey with keyAttr : Text data UpgradeData = UpgradeData with operator : Party invenkeys : [InvenKey] nums: [Int] outputData : Script UpgradeData outputData = do let ik0 = (InvenKey "key0attr") let ik1 = (InvenKey "key1attr") party <- allocateParty "Party" pure ( UpgradeData party [ik0,ik1] [0,1,2] )The output produced when I ran this script with the
--output-fileoption:{ "operator": "party-575096f2-7863-4a38-88d4-441642e61d23::1220c7f8a6da7b70b9daefea37d4d52b7114e5cedeb6df10e76467820af8410f9a9b", "invenkeys": [{ "keyAttr": "key0attr" }, { "keyAttr": "key1attr" }], "nums": [0, 1, 2] }