Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions bill_payments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub enum Error {
#[derive(Clone)]
#[contracttype]
#[derive(Clone)]
#[contracttype]
pub struct ArchivedBill {
pub id: u32,
pub owner: Address,
Expand Down
7 changes: 7 additions & 0 deletions indexer/examples/query-examples.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2026 Remitwise
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* Example queries demonstrating the indexer API
* Run with: ts-node examples/query-examples.ts
Expand Down
7 changes: 7 additions & 0 deletions indexer/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2026 Remitwise
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import Database from 'better-sqlite3';
import { QueryService } from './db/queries';

Expand Down
7 changes: 7 additions & 0 deletions indexer/src/db/queries.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2026 Remitwise
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import Database from 'better-sqlite3';
import { SavingsGoal, Bill, InsurancePolicy, RemittanceSplit } from '../types';

Expand Down
7 changes: 7 additions & 0 deletions indexer/src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2026 Remitwise
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import Database from 'better-sqlite3';

export function initializeDatabase(dbPath: string): Database.Database {
Expand Down
7 changes: 7 additions & 0 deletions indexer/src/eventProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2026 Remitwise
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import Database from 'better-sqlite3';
import { xdr } from '@stellar/stellar-sdk';

Expand Down
7 changes: 7 additions & 0 deletions indexer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2026 Remitwise
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import dotenv from 'dotenv';
import { initializeDatabase } from './db/schema';
import { Indexer } from './indexer';
Expand Down
7 changes: 7 additions & 0 deletions indexer/src/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2026 Remitwise
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { Server, SorobanRpc } from '@stellar/stellar-sdk';
import Database from 'better-sqlite3';
import { EventProcessor } from './eventProcessor';
Expand Down
7 changes: 7 additions & 0 deletions indexer/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2026 Remitwise
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// Database entity types
export interface SavingsGoal {
id: number;
Expand Down
7 changes: 7 additions & 0 deletions indexer/tests/eventProcessor.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2026 Remitwise
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* Unit tests for EventProcessor
* Run with: npm test
Expand Down
100 changes: 100 additions & 0 deletions insurance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,106 @@ impl Insurance {
);
}

// -----------------------------------------------------------------------
// Tag management
// -----------------------------------------------------------------------

fn validate_tags(tags: &Vec<String>) {
if tags.is_empty() {
panic!("Tags cannot be empty");
}
for tag in tags.iter() {
if tag.len() == 0 || tag.len() > 32 {
panic!("Tag must be between 1 and 32 characters");
}
}
}

pub fn add_tags_to_policy(
env: Env,
caller: Address,
policy_id: u32,
tags: Vec<String>,
) {
caller.require_auth();
Self::validate_tags(&tags);
Self::extend_instance_ttl(&env);

let mut policies: Map<u32, InsurancePolicy> = env
.storage()
.instance()
.get(&symbol_short!("POLICIES"))
.unwrap_or_else(|| Map::new(&env));

let mut policy = policies.get(policy_id).expect("Policy not found");

if policy.owner != caller {
panic!("Only the policy owner can add tags");
}

for tag in tags.iter() {
policy.tags.push_back(tag);
}

policies.set(policy_id, policy);
env.storage()
.instance()
.set(&symbol_short!("POLICIES"), &policies);

env.events().publish(
(symbol_short!("insure"), symbol_short!("tags_add")),
(policy_id, caller, tags),
);
}

pub fn remove_tags_from_policy(
env: Env,
caller: Address,
policy_id: u32,
tags: Vec<String>,
) {
caller.require_auth();
Self::validate_tags(&tags);
Self::extend_instance_ttl(&env);

let mut policies: Map<u32, InsurancePolicy> = env
.storage()
.instance()
.get(&symbol_short!("POLICIES"))
.unwrap_or_else(|| Map::new(&env));

let mut policy = policies.get(policy_id).expect("Policy not found");

if policy.owner != caller {
panic!("Only the policy owner can remove tags");
}

let mut new_tags = Vec::new(&env);
for existing_tag in policy.tags.iter() {
let mut should_keep = true;
for remove_tag in tags.iter() {
if existing_tag == remove_tag {
should_keep = false;
break;
}
}
if should_keep {
new_tags.push_back(existing_tag);
}
}

policy.tags = new_tags;
policies.set(policy_id, policy);
env.storage()
.instance()
.set(&symbol_short!("POLICIES"), &policies);

env.events().publish(
(symbol_short!("insure"), symbol_short!("tags_rem")),
(policy_id, caller, tags),
);
}

// -----------------------------------------------------------------------
// Core policy operations (unchanged)
// -----------------------------------------------------------------------
Expand Down
Loading