@btc-vision/transaction
Version:
OPNet transaction library allows you to create and sign transactions for the OPNet network.
52 lines (51 loc) • 1.24 kB
JavaScript
import { Map } from './Map.js';
export class AddressMap extends Map {
set(key, value) {
const index = this.indexOf(key);
if (index == -1) {
this._keys.push(key);
this._values.push(value);
}
else {
this._values[index] = value;
}
}
indexOf(address) {
for (let i = 0; i < this._keys.length; i++) {
const key = this._keys[i];
if (address.equals(key)) {
return i;
}
}
return -1;
}
has(key) {
for (let i = 0; i < this._keys.length; i++) {
if (key.equals(this._keys[i])) {
return true;
}
}
return false;
}
get(key) {
const index = this.indexOf(key);
if (index == -1) {
return;
}
return this._values[index];
}
delete(key) {
const index = this.indexOf(key);
if (index == -1) {
return false;
}
this._keys.splice(index, 1);
this._values.splice(index, 1);
return true;
}
*[Symbol.iterator]() {
for (const key of this._keys) {
yield [key, this.get(key)];
}
}
}