Skip to content

Commit

Permalink
migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
simke9445 committed Nov 29, 2023
1 parent 900d694 commit ad1e05f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
21 changes: 11 additions & 10 deletions contracts/warp-controller/src/migrate/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct OldJob {
pub labels: Vec<String>,
pub status: JobStatus,
pub terminate_condition: Option<String>,
pub duration_days: Uint64,
pub executions: Vec<Execution>,
pub vars: String,
pub recurring: bool,
Expand Down Expand Up @@ -61,15 +62,15 @@ pub fn migrate_pending_jobs(
let indexes = OldJobIndexes {
reward: UniqueIndex::new(
|job| (job.reward.u128(), job.id.u64()),
"pending_jobs__reward_v4",
"pending_jobs__reward_v5",
),
publish_time: MultiIndex::new(
|_pk, job| job.last_update_time.u64(),
"pending_jobs_v4",
"pending_jobs__publish_timestamp_v4",
"pending_jobs_v5",
"pending_jobs__publish_timestamp_v5",
),
};
IndexedMap::new("pending_jobs_v4", indexes)
IndexedMap::new("pending_jobs_v5", indexes)
}

let job_keys: Result<Vec<_>, _> = OLD_PENDING_JOBS()
Expand Down Expand Up @@ -100,7 +101,7 @@ pub fn migrate_pending_jobs(
recurring: old_job.recurring,
reward: old_job.reward,
assets_to_withdraw: old_job.assets_to_withdraw,
duration_days: Uint64::from(30u64),
duration_days: old_job.duration_days,
created_at_time: old_job.last_update_time,
// TODO: update to old_job.funding_account
funding_account: None,
Expand Down Expand Up @@ -131,15 +132,15 @@ pub fn migrate_finished_jobs(
let indexes = OldJobIndexes {
reward: UniqueIndex::new(
|job| (job.reward.u128(), job.id.u64()),
"finished_jobs__reward_v4",
"finished_jobs__reward_v5",
),
publish_time: MultiIndex::new(
|_pk, job| job.last_update_time.u64(),
"finished_jobs_v4",
"finished_jobs__publish_timestamp_v4",
"finished_jobs_v5",
"finished_jobs__publish_timestamp_v5",
),
};
IndexedMap::new("finished_jobs_v4", indexes)
IndexedMap::new("finished_jobs_v5", indexes)
}

let job_keys: Result<Vec<_>, _> = OLD_FINISHED_JOBS()
Expand Down Expand Up @@ -170,7 +171,7 @@ pub fn migrate_finished_jobs(
recurring: old_job.recurring,
reward: old_job.reward,
assets_to_withdraw: old_job.assets_to_withdraw,
duration_days: Uint64::from(30u64),
duration_days: old_job.duration_days,
created_at_time: old_job.last_update_time,
// TODO: update to old_job.funding_account
funding_account: None,
Expand Down
16 changes: 8 additions & 8 deletions contracts/warp-controller/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ pub fn PENDING_JOBS<'a>() -> IndexedMap<'a, u64, Job, JobIndexes<'a>> {
let indexes = JobIndexes {
reward: UniqueIndex::new(
|job| (job.reward.u128(), job.id.u64()),
"pending_jobs__reward_v5",
"pending_jobs__reward_v6",
),
publish_time: MultiIndex::new(
|_pk, job| job.last_update_time.u64(),
"pending_jobs_v5",
"pending_jobs__publish_timestamp_v5",
"pending_jobs_v6",
"pending_jobs__publish_timestamp_v6",
),
};
IndexedMap::new("pending_jobs_v5", indexes)
IndexedMap::new("pending_jobs_v6", indexes)
}

#[allow(non_snake_case)]
pub fn FINISHED_JOBS<'a>() -> IndexedMap<'a, u64, Job, JobIndexes<'a>> {
let indexes = JobIndexes {
reward: UniqueIndex::new(
|job| (job.reward.u128(), job.id.u64()),
"finished_jobs__reward_v5",
"finished_jobs__reward_v6",
),
publish_time: MultiIndex::new(
|_pk, job| job.last_update_time.u64(),
"finished_jobs_v5",
"finished_jobs__publish_timestamp_v5",
"finished_jobs_v6",
"finished_jobs__publish_timestamp_v6",
),
};
IndexedMap::new("finished_jobs_v5", indexes)
IndexedMap::new("finished_jobs_v6", indexes)
}

pub struct LegacyAccountIndexes<'a> {
Expand Down
8 changes: 4 additions & 4 deletions refs.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
"codeId": "9626"
},
"warp-controller": {
"codeId": "11718",
"codeId": "12126",
"address": "terra1fqcfh8vpqsl7l5yjjtq5wwu6sv989txncq5fa756tv7lywqexraq5vnjvt"
},
"warp-resolver": {
"codeId": "11717",
"codeId": "12124",
"address": "terra1lxfx6n792aw3hg47tchmyuhv5t30f334gus67pc250qx5zljadws65elnf"
},
"warp-templates": {
"codeId": "9263",
"address": "terra17xm2ewyg60y7eypnwav33fwm23hxs3qyd8qk9tnntj4d0rp2vvhsgkpwwp"
},
"warp-job-account": {
"codeId": "11716"
"codeId": "12123"
},
"warp-job-account-tracker": {
"codeId": "11630",
"codeId": "12122",
"address": "terra1zzgg30ygltd5s3xtescfquwmm2jktaq28t37f2j9h5wwswpxtyyspugek8"
}
},
Expand Down
8 changes: 5 additions & 3 deletions tasks/migrate_warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { MsgMigrateContract } from "@terra-money/terra.js";
import task, { info } from "@terra-money/terrariums";

task(async ({ deployer, signer, refs, network }) => {
// deployer.buildContract("warp-controller");
// deployer.optimizeContract("warp-controller");
deployer.buildContract("warp-controller");
deployer.optimizeContract("warp-controller");

await deployer.storeCode("warp-controller");
await new Promise((resolve) => setTimeout(resolve, 3000));
Expand All @@ -14,7 +14,9 @@ task(async ({ deployer, signer, refs, network }) => {
signer.key.accAddress,
contract.address!,
parseInt(contract.codeId!),
{}
{
warp_account_code_id: "12123"
}
);

try {
Expand Down

0 comments on commit ad1e05f

Please sign in to comment.