-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/alpha' into PE-5758
- Loading branch information
Showing
11 changed files
with
326 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/** | ||
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import { | ||
ANTContract, | ||
ANTRecord, | ||
ANTState, | ||
ContractConfiguration, | ||
EvaluationOptions, | ||
EvaluationParameters, | ||
SmartWeaveContract, | ||
isContractConfiguration, | ||
isContractTxIdConfiguration, | ||
} from '../types.js'; | ||
import { RemoteContract } from './contracts/remote-contract.js'; | ||
|
||
export class ANT implements ANTContract { | ||
private contract: SmartWeaveContract<ANTState>; | ||
|
||
constructor(config: ContractConfiguration) { | ||
if (isContractConfiguration<ANTState>(config)) { | ||
this.contract = config.contract; | ||
} else if (isContractTxIdConfiguration(config)) { | ||
this.contract = new RemoteContract<ANTState>({ | ||
contractTxId: config.contractTxId, | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the current state of the contract. | ||
*/ | ||
async getState(params: EvaluationParameters): Promise<ANTState> { | ||
const state = await this.contract.getContractState(params); | ||
return state; | ||
} | ||
|
||
async getRecord({ | ||
domain, | ||
evaluationOptions, | ||
}: EvaluationParameters<{ domain: string }>): Promise<ANTRecord> { | ||
const records = await this.getRecords({ evaluationOptions }); | ||
return records[domain]; | ||
} | ||
|
||
async getRecords({ | ||
evaluationOptions, | ||
}: { | ||
evaluationOptions?: EvaluationOptions | Record<string, never> | undefined; | ||
}): Promise<Record<string, ANTRecord>> { | ||
const state = await this.contract.getContractState({ evaluationOptions }); | ||
return state.records; | ||
} | ||
|
||
async getOwner({ | ||
evaluationOptions, | ||
}: { | ||
evaluationOptions?: EvaluationOptions | Record<string, never> | undefined; | ||
}): Promise<string> { | ||
const state = await this.contract.getContractState({ evaluationOptions }); | ||
return state.owner; | ||
} | ||
|
||
async getControllers({ | ||
evaluationOptions, | ||
}: { | ||
evaluationOptions?: EvaluationOptions | Record<string, never> | undefined; | ||
}): Promise<string[]> { | ||
const state = await this.contract.getContractState({ evaluationOptions }); | ||
return state.controllers; | ||
} | ||
|
||
async getName({ | ||
evaluationOptions, | ||
}: { | ||
evaluationOptions?: EvaluationOptions | Record<string, never> | undefined; | ||
}): Promise<string> { | ||
const state = await this.contract.getContractState({ evaluationOptions }); | ||
return state.name; | ||
} | ||
|
||
async getTicker({ | ||
evaluationOptions, | ||
}: { | ||
evaluationOptions?: EvaluationOptions | Record<string, never> | undefined; | ||
}): Promise<string> { | ||
const state = await this.contract.getContractState({ evaluationOptions }); | ||
return state.ticker; | ||
} | ||
|
||
async getBalances({ | ||
evaluationOptions, | ||
}: { | ||
evaluationOptions?: EvaluationOptions | Record<string, never> | undefined; | ||
}): Promise<Record<string, number>> { | ||
const state = await this.contract.getContractState({ evaluationOptions }); | ||
return state.balances; | ||
} | ||
|
||
async getBalance({ | ||
address, | ||
evaluationOptions, | ||
}: EvaluationParameters<{ address: string }>): Promise<number> { | ||
const balances = await this.getBalances({ evaluationOptions }); | ||
return balances[address]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.